4

We're looking to better manage test data using Cucumber in our Java test automation framework. For a Scenario Outline, we're looking to tabulate test parameters categorized by the applicable environment in which they will run. For example,

Scenario Outline: Login into application
Given I am on the homepage in the <environment>
When I enter my <user>
And I enter my <pass>
Then I am taken to the homepage
Examples:
|user    |pass     |environment|
|test    |test1    |local      |
|retest  |retest1  |sit        |
|prodtest|prodtest1|production |

So, when the above scenario is executing in, for example, the SIT environment, only the 2nd example will be picked up, and not the first and third.

Can this level of execution be accomplished?

rs79
  • 2,311
  • 2
  • 33
  • 39

2 Answers2

8

You can get this done by splitting up your examples table into two and using tags on them... Then run the test with the tags to filter in cucumberoptions.

@others
Examples:
|user    |pass     |environment|
|test    |test1    |local      |
|prodtest|prodtest1|production |

@sit
Examples:
|user    |pass     |environment|
|retest  |retest1  |sit        |
Grasshopper
  • 8,908
  • 2
  • 17
  • 32
  • 1
    Interesting. I wasn't aware that @tags can be applied to examples as well. I'll try this out. If it works, it should solve my question. Thanks so much! – rs79 Oct 19 '16 at 12:44
  • Also, does the scenario need to be tagged as "others" and "sit", or will the tagged example table take care of picking the applicable scenario for execution? – rs79 Oct 19 '16 at 12:45
  • Just use the tags on the example tables. Cucumber should do the rest of picking up the relevant tags. – Grasshopper Oct 19 '16 at 12:47
  • Good catch! usually using cucumber-jvm and didn'tk know that :) – troig Oct 19 '16 at 13:52
  • From which version of cucumber-jvm this is supported? – Purus Jul 10 '19 at 12:01
  • All i guess. answer is like 2 plus years old. To my knowledge this capability has not been removed. Which version are u using? – Grasshopper Jul 10 '19 at 13:21
  • @Grasshopper can we run specific test cases that are failed using tags that are applied at an example level. Note: I am using Cypress+cucumber+typescript – Hardik Rana Jan 23 '20 at 08:45
0

That is not what scenario outlines are designed for. You can write separate scenario's and then use tags on each one that you can then pass in at runtime which tag you want to run.

  • Doesn't quite fit the D-R-Y paradigm then :) – rs79 Oct 19 '16 at 12:41
  • Typically in Cucumber you won't have technical details like environment in your test cases. Scenario outlines are designed to run everything in the table and in that sense it is DRY. – Peter Gelderbloem Oct 19 '16 at 12:42