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?

2 Answers

1
Grasshopper On Best Solutions

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.

0
supputuri On

Not familiar with cucumber-jvm.

But, here is the general logic which should work (based on my ruby Cucumber knowledge)

In the hook, you can write the logic to under before method to get the scenario name scenario.name and then extract the TC.No. Compare the TC.No and skip if it's not part of your list. Here is the link which will give information how to skip the scenario (use this class in the before method) https://junit.org/junit4/javadoc/4.12/org/junit/AssumptionViolatedException.html

However, the best practice is to use the tags, it would have been easy if you had @TCId-xx tag. Still you can write a simple program that will scan all the feature files and update the scenarios with the tag based on the TC.No in the scenario name.