How to run cucumber scenario multiple time without using Scenario Outline How to run cucumber scenario multiple time without using Scenario Outline selenium selenium

How to run cucumber scenario multiple time without using Scenario Outline


First of all Scenario Outline is designed to be used in cases when your input data is changing. So that doesn't fit your case in the first place.

AFAIK you have the following options:

Set the logic internally in the step. Meaning looping through the required actions inside you step glue code.

@Then("^Repetitive step$")public void repetitive_step(final String repetitions) throws Throwable {int reps = Integer.valueOf(repetitions);    for(int i=0; i<reps; i++){        // your step code    }    }

Repeat your step in the feature file itself. So if that's just a one time occasion that you want to try and do not care about the aesthetics, you can just copy paste the scenario as many times as you need in the feature file.


It sounds like what you're looking for is a for loop inside of a Scenario. I've seen this similar problem around a couple of places, but the best you can do for now is simply design your feature so that your preliminary steps are defined in the background and then you have a scenario outline that loops through your section.

If you're available to using a different framework, I've been working on a project called Kherkin that allows you to loop a specific part of your scenario and many other things things that regular Gherkin doesn't allow you to do. Here is an example of how you would loop only a section of your scenrio:https://bitbucket.org/Muhatashim/zarif-kherkin/src/master/src/test/kotlin/org/bitbucket/muhatashim/kherkin/lang/script/IterationTest.kt

To learn more about Kherkin: https://bitbucket.org/Muhatashim/zarif-kherkin/src/master/