Search code examples
javamavencucumbercucumber-jvmcucumber-java

Get list of scenarios by given cucumber tags


I need to get the list of all the scenarios and tags that are going to be run when I execute a certain condition. For example when I run the command

mvn clean test -Dcucumber.filter.tags='@Regression and @login

A list of test cases that come from different features is executed, but to obtain that list I must wait for the execution of the suite to finish completely.

I would like to know if there is any way to get that list before the execution starts or at least at the beginning. Currently I do it manually but it takes a long time because there are many test cases

If you have any information to do it with cucumber or maven I would be very grateful.


Solution

  • In your CucumberOptions, you can use dryRun = true. It prints the list of scenarios which are going to be executed. Remember dryRun purpose is different but you can use that in your case.

    CucumberOptions

    @CucumberOptions(features = "src\\test\\resources\\features", glue = { "cucumberStep" }, dryRun = true, plugin = {
            "pretty", "html:report/TestReport.html" }, monochrome = true, stepNotifications = true, tags = "@Test4  and @Test")
    

    Output:

    @Regression @Test
    Scenario Outline: decision                                                       # src/test/resources/features/xPeriment.feature:26
      When I populate the "Decision Title" field with "testinput "user1" titlepart2" # cucumberStep.stepDef.populate(java.lang.String,java.lang.String)
    
    @Regression @Test
    Scenario Outline: decision                                                       # src/test/resources/features/xPeriment.feature:27
      When I populate the "Decision Title" field with "testinput "user1" titlepart2" # cucumberStep.stepDef.populate(java.lang.String,java.lang.String)
    
    @Regression @Test
    Scenario Outline: decision                                                       # src/test/resources/features/xPeriment.feature:28
      When I populate the "Decision Title" field with "testinput "user1" titlepart2" # cucumberStep.stepDef.populate(java.lang.String,java.lang.String)
    
    @All @Test4
    Scenario: Verify the content of the pdf file_1. # src/test/resources/features/xPeriment2.feature:20