I have 8 cucumber-jvm
scenarios and the very first scenario measures the page load time and environment availability. In order to avoid unnecessary runs, if the first scenario is failed - for instance, the environment is not available, or loading too slowly - all other scenarios should be skipped.
How can I do that?
My CucumberOptions
:
@RunWith(Cucumber.class)
@CucumberOptions(
strict = true,
features = {"src/test/resources/features"},
glue = {"stepDefinitions"},
format = { "progress", "html:target/Results",
"json:target/Results/cucumber.json"},
tags = {"@test"})
public class TestRunner {
}
Thanks!
Skip feature or scenario in cucumber? You can ignore or skip Cucumber Tests using tags. This works both for Scenario as well as Feature. You can skip a scenario, set of scenarios or all scenarios in a feature file.
How can I skip the passed test cases and execute only the failed one through listeners ? Every time before the start of the scenario, it should go to the listener and check the excel sheet whether the scenario is passed or fail. If passed then the scenario should be skipped.
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.
You can make use of Assume.assumeTrue(false)
to skip tests. But this will require some changes in test runner and code changes.
tags
a value of @Smoke. Other option values default to what you have.@RunWith(Cucumber.class) @CucumberOptions(plugin={ }, tags={"@Smoke"}, glue=" ", features=" ") public class RunFirstTest {
Add the @Smoke
tag to the scenario in the feature file that checks the environment etc. Optionally you could look at splitting the feature files.
Create a new class to hold a static flag. It is a simple implementation you might look at making this more robust.
public class SkipFlag { public static boolean skipFlag = false; }
After hook
with the value option set to @Smoke
. Thus it will run only for the smoke scenario.@After(value={"@Smoke"}) public void afterSkip(Scenario scen) { if(scen.isFailed()) SkipFlag.skipFlag = true; }
tags
value of @MainTests. Other option values default to what you have.
@RunWith(Cucumber.class) @CucumberOptions(plugin={" "}, tags={"@MainTests"}, glue=" ", features=" ") public class RunMainTest {
@BeforeClass public static void before() { if(SkipFlag.skipFlag) Assume.assumeTrue(false); } }
Add the @MainTests
tag to the other scenarios in the feature file. Optionally you could look at splitting the feature files and give the name of the feature file in the features option value.
Run this by using maven failsafe plugin. In the configuration of this plugin add the inclusion of these 2 runners in the pom.xml.
<configuration> <includes> <include>RunFirstTest</include> <include>RunMainTest</include> </includes> <runOrder>alphabetical</runOrder> </configuration>
The includes part might be optional if you only have 2 runners. The most important point is that the RunFirstTest
should be the first to run, so alphabetically should be first.
Hope it works.
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