I wanted to run Cucumber Feature file based on the Test case ID that scanerio name contains.
I know we can use @CucumberOptions 'features' tag and specify the line number to execute e.g "src/test/resources/Folder/myfile.feature:7:12" This will run scenarios at line 7 and 12. But i wanted to run based on the TC ID.
Below is the feature file code
@Run
Feature: Login Functionality
Scenario: First Test Case(TC.No:1)
Given I perform action 1
Scenario: Second Test Case(TC.No:2)
Given I perform action 2
Scenario: Third Test Case(TC.No:3)
Given I perform action 3
Scenario: Fourth Test Case(TC.No:4)
Given I perform action 4
Scenario: Fifth Test Case(TC.No:5)
Given I perform action 5
All the scenario's are in a single feature. For the feature file code above i wanted some way through which i can execute based on TC Id. E.g I only want to execute TC1,TC2 and TC5( TC id's picked up from scenario names).
There is a property file that contains the TC Id's to be executed. My code should read the file and then execute only those TC id's. This can help me in reducing the number of automation TC's to be run. Is it possible?
You can use the name
property of @CucumberOptions
or use the '-n'
option if you are using the cli option. It also supports regular expressions.
To run TC.No:1 and TC.No:4 use something like this
@CucumberOptions(name = { "TC.No:1|TC.No:4" })
or
@CucumberOptions(name = { "TC.No:1","TC.No:4" })
You can get more details at this link.
As you are reading the ids from a file, the second option is the best. Use the cucumber.api.cli.Main
class main()
method to execute the features. You can create the options dynamically. Refer to this post.
CLI reference docs.