Careeroza
Tags and the TestNG Runner
Tags
Tags like @smoke, @regression or @wip group scenarios. Tag expressions use and, or, not.
| Expression | Runs |
|---|---|
@smoke | scenarios tagged smoke |
@smoke or @payments | either tag |
@regression and not @wip | regression except work in progress |
Runner Class
import io.cucumber.testng.*;
import org.testng.annotations.DataProvider;
@CucumberOptions(
features = "src/test/resources/features",
glue = {"com.shopease.steps", "com.shopease.hooks"},
tags = "@regression and not @wip",
plugin = {"pretty", "html:target/cucumber-report.html", "json:target/cucumber.json",
"rerun:target/failed-scenarios.txt"},
monochrome = true)
public class TestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true) // run scenarios in parallel threads
public Object[][] scenarios() {
return super.scenarios();
}
}Example
Override the tags from the command line:
mvn test -Dcucumber.filter.tags="@smoke"Example output
@smoke Scenario: Valid login # features/login.feature:9 Given the user is on the login page # LoginSteps.onLoginPage() When the user logs in with "[email protected]" and "Secret@123" # LoginSteps.logsIn(String,String) Then the welcome message "Welcome, Asha" is shown # LoginSteps.welcomeShown(String) 4 Scenarios (4 passed) 13 Steps (13 passed) 0m18.902s [INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] BUILD SUCCESS
Note
Note: The rerun plugin writes failed scenarios to a file. A second runner with features = "@target/failed-scenarios.txt" re-runs only those, a common CI trick.