Category:
BDD Cucumber
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. Then to target these tagged scenarios just specify the tags names in the CucumberOptions as tags = {“@SmokeTests”}.
@FunctionalTest
Feature: ECommerce Application
@SmokeTest @RegressionTest
Scenario: Successful Login
Given This is a blank test
@RegressionTest
Scenario: UnSuccessful Login
Given This is a blank test
package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = ""Feature""
,glue={""stepDefinition""}
,dryRun=true
,monochrome = false
,format = {""pretty"", ""html:target/Destination""} )
,tags={""smokeTest""}
)
public class TestRunner {
}
Execute all tests tagged as @SmokeTest OR @RegressionTest : tags = {"SmokeTest,RegressionTest"}
Execute all tests tagged as @SmokeTest AND @RegressionTest : tags = {"SmokeTest", "RegressionTest"}
Execute all tests of the feature tagged as @FunctionalTests but skip scenarios tagged as @SmokeTest : tags = {"FunctionalTest","~SmokeTest"}