Cucumber Configuration

You can specify configuration options for Cucumber in a cucumber.yml or cucumber.yaml file. This file must be in a .config directory, or config subdirectory of your current working directory.

Defining Profiles

config/cucumber.yml
## ##YAML Template
html_report: --format progress --format html --out=features_report.html
bvt: --tags @bvt

Defining a template requires a name and then the command-line options that you want to execute with this profile.

The example above generates two profiles:

  1. html_report, with a list of command-line options that specify new output formats, and
  2. bvt, which executes all Features and Scenarios tagged with @bvt.

Executing Profiles

\[[email protected] project] cucumber --profile html_report
\[[email protected] project] cucumber -p bvt

Use the flag --profile or -p to execute Cucumber with a profile. You can still use other command line arguments alongside --profile or -p, if desired.

\[[email protected] project] cucumber --profile html_report --tags [email protected]

Multiple profiles can even be specified together. The following executes all Features and Scenarios tagged @bvt, with the specified progress and HTML output.

\[[email protected] project] cucumber -p html_report -p bvt

Default Profile

Chances are you’ll want to execute Cucumber with a particular profile most of the time. The Cucumber configuration file uses a default profile to provide this functionality. When you specify a default profile, you are telling Cucumber to use the default command-line options whenever you don’t explicitly specify a different profile.

Using the same example, perhaps we want the html_report profile to be our default execution.

1. config/cucumber.yml
   ## ##YAML Template
   default: --profile html_report --profile bvt
   html_report: --format progress --format html --out=features_report.html
   bvt: --tags @bvt
\[[email protected] project] cucumber

With this setup, Cucumber will now use both the bvt profile and html_report profile, testing all Features and Scenarios tagged with @bvt, along with the progress output and HTML output.

Preprocessing with ERB

The cucumber.yml file is preprocessed by ERB (Embedded RuBy). This allows you to use Ruby code to generate values in the cucumber.yml file.

So, if you have several profiles with similar values, you might do this:

1. config/cucumber.yml
   ## ##YAML Template
   <% common = "--tags [email protected] --strict" %>
   default: <%= common %> features
   html_report: <%= common %> --format html --out=features_report.html features

Environment Variables

You can use environment variables in the profile argument list, just as you would normally specify them on the command-line.

1. config/cucumber.yml
   \##YAML Template
2. ## ie profile executes the browser features with Internet Explorer
   default: --profile html_report --profile bvt
   html_report: --format progress --format html --out=features_report.html
   bvt: --tags @bvt
   ie: BROWSER=IE

When running Cucumber, it can sometimes be handy to pass special values to Cucumber for your step definitions to use.

You can do this on the command line:

   cucumber FOO=BAR --format progress features

You can now pick up ENV\['FOO'] in Ruby (for example, in env.rb, or a Step Definition) and perform actions according to the value.

You can also do this in cucumber.yml.

For example, the following sets up a profile that runs the specified Tag and sets an environment variable:

   baz: --tags @mytag FOO=BAR

You can help us improve this documentation. Edit this page.