问题
I need to execute one scenario which is part of one feature 100 times. There is no scenario outline as there is no data parameterization. I just need to perform gorilla testing on this particular scenario so as to make sure it passes every single time without any fail. Some of my team members observed failure a couple of times, so need to validate the stability.
Runner class code:
public class Baserunner extends AbstractTestNGCucumberTests{ private TestNGCucumberRunner testNGCucumberRunner;
@BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
System.out.println("Test");
String browsername = "IExplorer";
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
BaseConfig.ConfigFileReader();
BaseConfig.launchbrowser(browsername);
// BaseConfig.executeScript();
}
@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}
@DataProvider
public Object[][] features() {
return testNGCucumberRunner.provideFeatures();
}
@AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
testNGCucumberRunner.finish();
BaseConfig.closeBrowser();
}
回答1:
You could try this below hack with a looping logic in the runner class.
@Override
@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
for(int i=0;i<100;i++)
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}
Plus you have to make sure only one scenario is executed by specifying the line number.
@CucumberOptions(features = {"src/test/resources/stepdef/scenarios.feature:3"})
What version of cucumber are you using?
回答2:
I think that you need to parameterize It Scenario in cucumber for example. This execute every scenario's step so many times has tag
Scenario Outline: My program's test
Given Im in the section HOME
When I click on button Accept <action>
Example:
| action |
| 1 |
| n |
| n |
| 100 |
Another option would be that. This execute with a parameterize | 100 |
Scenario: My program's test
Given Im in the section HOME
When I click on button Accept 100
After In step definition
@When("^I click on button Accept \"([^\"]*)\"$")
public void I_click_on_button_Accept(int n) throws Throwable {
for(int i=0; i <= n; i++) {
methodCall();
}
}
来源:https://stackoverflow.com/questions/57774655/how-to-execute-same-cucumber-feature-or-scenario-n-times