Bhavik Shah
Bhavik Shah

Reputation: 140

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.

Upvotes: 4

Views: 8576

Answers (3)

user861594
user861594

Reputation: 5908

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

Upvotes: 1

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.

Upvotes: 2

Matthewek
Matthewek

Reputation: 1559

To share 'examples' data, you could store them in external static file (json/txt/what ever) and load them in particular steps implementation. I am not aware of out of the box solution in cucumber to share example between feature files.

Upvotes: 0

Related Questions