vsingh
vsingh

Reputation: 135

How to execute same cucumber feature or scenario n times?

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();
}

Upvotes: 1

Views: 4907

Answers (3)

Ricardo De Leon
Ricardo De Leon

Reputation: 41

Maybe not the best answer but it worked for me.

Running on the terminal MacOs system.

Tested on a Playwright framework.

max=10
n=10
while [[ $n -lt $max ]]; do
  your maven command here
  ((n++))
  sleep 3
done

Upvotes: 0

Johans Susarte
Johans Susarte

Reputation: 1

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();
  }
}

Upvotes: -1

Grasshopper
Grasshopper

Reputation: 9058

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?

Upvotes: 2

Related Questions