How to run multiple feature files using the cucumb

2019-05-11 06:05发布

问题:

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.

回答1:

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
....


回答2:

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 |
  | a@gmail.com| 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"} )


回答3:

Modified my code like to run all enabled features, scenarios. features is the point to note here for the runner class to consider the features

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:features"},
        plugin = {"html:target/site/cucumber-pretty","json:target/cucumber.json"},
        tags = {"@currentTest"},
        glue={"helpers","stepDefinitions"},
        //      dryRun = true,
        monochrome = true
        )
public class RunCukesTest{

}


回答4:

@RunWith(Cucumber.class)

@CucumberOptions(
features = {"src/test/java/Features"},
tags= {"@FirstTimeLaunch, @SignUpPage"},
glue= {"testCode"},
plugin = { "pretty", "html:target/htmlreports" }
)

Here all *.feature files inside your Features folder (Package) will be executed in the Alphabetic order of the file name, when you execute as a Junit test ( runner class )