简体   繁体   中英

Is there a way to run only selective examples from a cucumber scenario outline?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM