scenario outlines

a single scenario outline provides tables of input data and expected output. It consists of a bunch of similar scenario.

Two differences from scenario:

1) use keyword Scenario Outline instead of Scenario

2) Variable data in angle brackets

scenarios keyword is followed by rows of example data.



Tags are a great way to organise your features and scenarios. Consider this example:

Feature: Verify billing

  Scenario: Missing product description

  Scenario: Several products

A Scenario or feature can have as many tags as you like. Just separate them with spaces:

@billing @bicker @annoy
Feature: Verify billing

Tag Inheritance

Any tag that exists on a Feature will be inherited by Scenario, Scenario Outline or Examples.

Running a subset of scenarios

You can use the --tags option to tell Cucumber that you only want to run features or scenarios that have (or don’t have) certain tags. Examples:

cucumber --tags @billing            # Runs both scenarios
cucumber --tags @important          # Runs the first scenario
cucumber --tags ~@important         # Runs the second scenario (Scenarios without @important)

cucumber --tags @billing --tags @important    # Runs the first scenario (Scenarios with @important AND @billing)
cucumber --tags @billing,@important           # Runs both scenarios (Scenarios with @important OR @billing)

(Another way to “filter” what you want to run is to use the file.feature:line pattern or the --scenario option as described in Running Features).

cucumber Features In Subdirectories

From this blog
I’m working on a project where we’ve amassed a decent amount of Cucumber features. Dumping them in the root directory makes it difficult to find the feature you’re looking for and running related features is impossible.

I’ve fooled with organizing my cucumber features in the past, but didn’t have much luck. Grouping related features into subdirectories was fine when running the entire suite, but running an individual feature failed because Cucumber doesn’t know to load step definitions from the parent directory. As I was looking through cucumber –help the other day, I happened to notice the –require flag.

-r, –require LIBRARY|DIR
Require files before executing the features.

Running the following command was exactly what I needed.

cucumber –require features features/users/sign_in.feature

This tells Cucumber to load all .rb files under features/ which will find the step definitions and support files. To save some typing, I created an alias in ~/.bashrc.

alias cuc=’cucumber -r features’

Where I’ve really enjoyed this setup is when running all related features. After touching a step definition, I’d like to run the features that depend on it quickly without running the entire suite. Now that’s as simple as:

cuc features/users/*