1

I have a Cucumber .feature file with scenario outline like below.

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |    12 |   5 |    7 |
    |    20 |   5 |   15 |

Is there a way to run only specific row(s) from the examples table during a test run?

Right now, I need to split this into two scenario outlines and tag one of them as @ignore to accomplish this.

Does cucumber provide a way to filter examples during execution, maybe based on a column in the example table?

vivek_ganesan
  • 658
  • 4
  • 19

2 Answers2

1

Assuming you're using Cucumber with JUnit 5, you can use:

@SelectClasspathResource(value = "com/example/application.feature", line = 42)

This will run the example on line 42.

If you're using Cucumber with JUnit 4, you can use:

@CucumberOptions(features = "com/example/application.feature:42")

Though as you are also using Serenity, neither may work.

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
  • Thanks for your answer @m-p-korstanje Is there a documentation pointing to `SelectClasspathResource` option you detailed above? – vivek_ganesan Aug 15 '22 at 15:41
  • I reckon https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine and https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine should get you pretty far. – M.P. Korstanje Aug 15 '22 at 16:14
  • Or the skeleton project, https://github.com/cucumber/cucumber-java-skeleton – M.P. Korstanje Aug 15 '22 at 16:14
1

I found a pretty neat way to do this in the Cucumber docs after I read them extra-carefully.

The answer is directly in this page

It is possible to tag specific examples in the way given below:

Scenario Outline: Steps will run conditionally if tagged
  Given user is logged in
  When user clicks <link>
  Then user will be logged out

  @mobile
  Examples:
    | link                  |
    | logout link on mobile |

  @desktop
  Examples:
    | link                   |
    | logout link on desktop |

This serves my purpose.

vivek_ganesan
  • 658
  • 4
  • 19