1

I'm writing test using Java, Intellij, Selenium + Cucubmer. I have a simple test scenario:

  Scenario: Add X random products to the shopping cart

      Given I choose a random product from a list
      When I add random quantity of the product to the shopping cart
      Then I see that number of products in the cart was updated

After last step I should go to first step and repeat all process X times. I don't know how to achieve it within one scenario without copying steps. Is it possible to run steps 1-3 in a loop?

David Avsajanishvili
  • 7,678
  • 2
  • 22
  • 24
wawr
  • 21
  • 1
  • 4

2 Answers2

1

You can convert this into a dummy ScenarioOutline like below and extend the examples table to whatever times you want.

  ScenarioOutline: Add X random products to the shopping cart

      Given I choose a random product from a list
      When I add random quantity of the product to the shopping cart
      Then I see that number of products in the cart was updated

    Examples:
    | id |
    | 1  |
    | 2  |
    | 3  |

Another way is to hack the runner code but this will only work for a single scenario you want repeated. How to execute same cucumber feature or scenario n times?

Grasshopper
  • 8,908
  • 2
  • 17
  • 32
  • I don't want to repeat whole scenario instead I would like to jump to step Given and start from there. Why is it so important within the the scenario. – wawr Oct 03 '19 at 17:31
0

Try using following

Scenario: Add X random products to the shopping cart

      * configure retry = { count: <no-of-counts>, interval: <interval-between-each-retry-in-ms>}
      Given I choose a random product from a list
      And retry until <your-conditions>
      When I add random quantity of the product to the shopping cart
      Then I see that number of products in the cart was updated

Example:

Scenario: Add X random products to the shopping cart

      * configure retry = { count: X, interval: 0}
      Given I choose a random product from a list
      And retry until true
      When I add random quantity of the product to the shopping cart
      Then I see that number of products in the cart was updated

Here i have used count X as i have to add X random products and don't want to wait between them so the interval is 0 ms. I have also made the condition to be always true since i want to run for X without any conditions. You can write some condition like X==Y or X>Y or any other expression which results in a boolean value.