4

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.

Bhavik Shah
  • 140
  • 4
  • 16
  • Does this answer your question? [Sharing a common set of Examples across multiple Scenario Outlines in Specflow](https://stackoverflow.com/questions/8120779/sharing-a-common-set-of-examples-across-multiple-scenario-outlines-in-specflow) – Jérôme MEVEL Nov 23 '21 at 13:37

3 Answers3

2

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.

TheSociety
  • 1,936
  • 2
  • 8
  • 20
1

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

user861594
  • 5,733
  • 3
  • 29
  • 45
  • Hi, I was searching for an answer for "How to write step definition file" of the above example in Cypress.... Do you know how? thanks a lot https://stackoverflow.com/questions/63930551/how-to-parameterize-dropdown-list-in-cypress-with-cucumber-feature-file – user3601310 Sep 19 '20 at 09:21
0

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.

Matthewek
  • 1,519
  • 2
  • 22
  • 42
  • Thanks @Matthewek . But while reporting this, will it be display like single scenario with every example (like scenario outline) ? – Bhavik Shah Apr 11 '19 at 12:16