2

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?

2 Answers 2

2

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.

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.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.