How to run multiple tags from testrunner class file in cucumber framework using @tags?
Solution 1
Here's a sample cucumber Junit runner template:
@RunWith(Cucumber.class)
@CucumberOptions(features = { "classpath:features/*.feature" }, glue = "packagename(s) or class name(s) containing the step definitions", plugin = {
"pretty:target/prettyReport.txt", "html:target/cucumber", "json:target/cucumber.json", "rerun:target/rerun.txt",
"junit:target/junit-report.xml", "testng:target/testng-output.xml" }, monochrome = true, tags = {"~@Ignore"})
public class FeatureRunnerTest {
}
Hope this helps!!
EDIT: "~" symbol..is used for negation..that is run all the features except one's marked with Ignore tag..On the other hand u can specify list of tags in the tags attribute comma seperated to run only those tests
Solution 2
For multiple tags Cucumber uses logical AND and logical OR. For example, the below works fine for me.
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/cucumber-report.html"},
features= "Features",
glue= {"com.cucumber.stepdefinition"},
tags= "@RegressionTest or @SmokeTest"
)
public class TestRunner {
}
Solution 3
See the below implemtation of multi tag form cucumber rummer:
@CucumberOptions( features = "src/test/java/features", glue="stepDefinations", tags = "@Test_Working_Calendar,@Test_email_tempalte", plugin = {"pretty","html:target/cucumber" ,"json:target/cucumber.json" ,"junit:target/cukes.xml" ,"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"})
tsr_qa
Currently working as Automation Engineer in reputed organization. I love to work in selenium automation
Updated on July 06, 2022Comments
-
tsr_qa almost 2 years
@RunWith(Cucumber.class) @CucumberOptions( plugin = {"pretty","html:target/html/automation"}, features = {"resource/***.feature"}, glue={}, tags={"@login","@Products"} )
This is my feature files
@login
Feature: Login to Application
Scenario: this is verify the application is logged successfully Given Navigate to Panasonic application Then Verify the title of the application Then Logout the application
@Products
Feature: Login to Application
Background: user should be navigate to home page of application
Given User login to home page with valid credentials
When click the catalog link on home page
Scenario : To verify whether able to create more than ten products in products page
And check the sub menu of catalog is displaying in header
And check the My product catalog table
-
Mrunal Gosar about 8 yearsyou have not specified the glue code which is why probably it is not working. please specify the glue code and that should be it
-
tsr_qa about 8 years@MrunalGosar what i have to specify in glue code? is package name of step definition? or anything else?
-
-
tsr_qa about 8 yearsNow i got some clear points from your comment. I need clarification in your comment. Here u have mentioned tags = {"~@Ignore"} instead of this tags, shall i use my tags={"~@login","~@Products"} like this???