Using the below line of code, all scenarios mentioned in login.feature can be executed.
@CucumberOptions(features= "src/main/resources/publish/login.feature", format = {"pretty"} )
If I have to execute multiple feature files, how do I define? Assuming if I define as below, features mentioned in publish folder would be executed.
@CucumberOptions(features= "src/main/resources/publish", format = {"pretty"} )
If I have to run multiple features and scenarios inside it, how do I define? Do i have to create multile cucumberRunner classes or i can define in one class file.
Cucumber can be executed in parallel using TestNG and Maven test execution plugins by setting the dataprovider parallel option to true. In TestNG the scenarios and rows in a scenario outline are executed in multiple threads. One can use either Maven Surefire or Failsafe plugin for executing the runners.
How to Run Multiple Scenarios in Cucumber. You can execute multiple scenarios in a single or multiple feature file by tagging Scenarios with common tags or grouping them using the rule keyword and tags. And Later, you can execute the scenarios by using that tag in the Cucumber Runner or Command line.
Cucumber can be executed in parallel using JUnit and Maven test execution plugins. In JUnit, the feature files are run in parallel rather than scenarios, which means all the scenarios in a feature file will be executed by the same thread. You can use either Maven Surefire or Failsafe plugin to execute the runner.
We can define each scenario with a useful tag. Later, in the runner file, we can decide which specific tag (and so as the scenario(s)) we want Cucumber to execute. Tag starts with “@”. After “@” you can have any relevant text to define your tag like @SmokeTests just above the scenarios you like to mark.
You can do it by defining tags value in cucumber option(considering that you have already grouped those scenarios in feature files)
Eg: features="src/test/resources/FeatureFiles",tags="@feature1scenariogroup1,@feature2cenariogroup2"
Defining Tags Inside Feature File:
Feature: My Feature File
@smoke
Scenario: Login
Given I open "FireFox" browser
When I navigate to Sectionone "Home" page
And i do something
Then I Validate Something
@regression
Scenario: Compose Email
Given I open "FireFox" browser
When I Do An Action
@OnlyOneTime
Scenario:Send Email
....
You can either use selective feature file or selective scenarios in the feature using tags. Please try with this solution.
Lets consider the you have n number of feature files and you need to run only selective feature from that. Then name each feature file with @tag name.
eg.: Under this folder, if you are having n number of features - "src/main/resources/publish"
1st Feature file name:
Login.feature
//Inside the file start with feature tag name
@Login
Feature: To Login to Email
//Then feature name followed with scenario tag name
@User
//Scenario1:
Scenario Outline: Navigate and logon to gmail application
Given User launches gmail application
When User updates emailID <emailID>
And User updates pwd <pwd>
Then User clicks on Login Button
Examples:
| emailID | pwd |
| [email protected]| 123 |
2nd Feature File name:
CreateEmail.feature
@Createmail
Feature: Create email
Scenario: Blah blah blah...
//Write all Given when And Then
3rd Feature File name:
SendEmail.feature
@Sendemail
Feature: Send email
Scenario: Blah blah blah...
//Write all Given when And Then
So From the above Test files. Lets consider you want to test 1st and 3rd feature alone, Then you can use code as below:
eg.: # This is to run specific feature files, which is 1 and 3. Likewise you can use the tags for scenario as well if you have n number scenario in same feature file.
@CucumberOptions(features= "src/main/resources/publish", tags="@Login, @Sendemail", format = {"pretty"} )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With