Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I repeat steps without repeating the steps using Cucumber?

Tags:

ruby

cucumber

I need to test behaviour that triggers when a user repeats a set of actions many times. I would like to end up with a scenario that looks something like this:

Scenario: Nice way
  Given that I am on some screen
  When I enter something into some text field
  And I press the Continue button
  And I go back
  And I repeat the previous 2 steps 5 times
  Then the application should crash

Rather than a scenario that looks like this:

Scenario: Annoying way
  Given that I am on some screen
  When I enter something into some text field
  And I press the Continue button
  And I go back
  And I press the Continue button
  And I go back
  And I press the Continue button
  And I go back
  And I press the Continue button
  And I go back
  And I press the Continue button
  And I go back
  And I press the Continue button
  And I go back
  Then the application should crash

Is there a standard way of doing this or do I have to implement it myself?

like image 278
Erik B Avatar asked Mar 11 '23 09:03

Erik B


1 Answers

If you have control over the step definition code try a step like this -

And I press Continue button and go back 5 times

Capture the number of times in the step definition with a variable and call existing functions in a loop for the number of times.

It can be captured by something like:

@And("^I press Continue button and go back (//d+) times")
public void iPressContinueButtonAndGoBackNTimes(int n){
    //enter code here
}
like image 199
Grasshopper Avatar answered May 05 '23 14:05

Grasshopper