Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use same set of examples in multiple scenario outlines in cucumber features

I tried finding this solution but no luck. Its very simple requirement and I think cucumber has solution which I am not aware of.

I want to use same set of examples of scenario outlines to the multiple features. Every time I don't want to copy paste same set of example, it will lead to non-maintainability of feature files.

I tried with cucumber java with below example

Given The Economy is up for actions
    When I make GET request to get **device** list with limit as <limit>
    Then I should get success status as true
    And I should get the **device** list with <limit> members

    Examples:
      | limit |
      | 1     |
      | 10    |
      | 25    |


Given The Economy is up for actions
    When I make GET request to get **user** list with limit as <limit>
    Then I should get success status as true
    And I should get the **user** list with <limit> members


    Examples:
      | limit |
      | 1     |
      | 10    |
      | 25    |

Here you can see only When step is making difference, where in both steps limit examples are same. This is just an example, I have lot many cases like this in which I need to use different set of examples.

One thing which I love about testNG is data providers which will solve this problem easily. But looking forward to get similar in cucumber.

like image 601
Bhavik Shah Avatar asked Oct 27 '25 11:10

Bhavik Shah


2 Answers

Cucumber does not provide such flexibility where we write examples/data tables only once in a feature file and access these in all other feature files.

Other side, if you do not use scenario outline in that case depending on data variation under examples lets say 3, you would have to write 3 different scenario.

like image 89
TheSociety Avatar answered Oct 29 '25 23:10

TheSociety


If you are looking features similar to TestNG while using BDD/Gherkin, you should try pure TestNG implementation of BDD including gherkin. It is pure TestNG implementation for BDD provides all TestNG features including priority, dependency, listeners, parallel execution. It is designed for web, mobile and web-service functional test automation, providing design concepts and lots of inbuilt features required to support different use cases.

Refer

  • reusable-generic-examples-table-in-cucumber
  • examples-in-cucumber
  • customdataprovider-for-feature-file
  • creating-examples-for-scenariooutline-in-code
like image 45
user861594 Avatar answered Oct 30 '25 01:10

user861594



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!