---
title: Cucumber.rb
description: Learn how to integrate Allure with Cucumber.rb to generate rich, interactive test reports. Follow step-by-step setup, test execution, and report generation guidance.
---

# Getting started with Allure Cucumber.rb

[![Allure Cucumber.rb gem latest version](https://img.shields.io/gem/v/allure-cucumber?style=flat "Allure Cucumber.rb gem latest version")](https://rubygems.org/gems/allure-cucumber)

Generate beautiful HTML reports using [Allure Report](https://allurereport.org/docs/) and your [Cucumber.rb](https://cucumber.io/docs/installation/ruby/) tests.

Info:
Check out the example project at [github.com/allure-examples/allure-cucumber-example](https://github.com/allure-examples/allure-cucumber-example) to see Allure Cucumber.rb in action.

## Setting up

### 1. Prepare your project

1. Install the Allure Report command-line tool, if it is not yet installed in your operating system. Note that Allure Report requires Java, see the [installation instructions](/docs/v2/install/).

1. Add Allure Cucumber.rb to your project's `Gemfile`. For example:

   ```ruby
   source 'https://rubygems.org'

   gem 'allure-cucumber', '~> 2.23.0'
   gem 'cucumber', '~> 9.1'
   ```

1. Open a terminal, go to the project directory and install the dependencies from the `Gemfile`. For example, if you use [Bundler](https://bundler.io/):

   ```bash
   cd /home/user/myproject
   bundle install
   ```

1. In the project's [`cucumber.yml`](https://cucumber.io/docs/cucumber/configuration/?lang=ruby) file, specify the Allure's formatter for Cucumber.rb.

   ```yaml
   default: --format AllureCucumber::CucumberFormatter
   ```

### 2. Run tests

Run your Cucumber.rb tests same way as your would run them usually. For example:

```bash
bundle exec cucumber
```

This will save necessary data into `allure-results` or other directory, according to the [Configuration](/docs/cucumberrb-configuration/). If the directory already exists, the new files will be added to the existing ones, so that a future report will be based on them all.

### 3. Generate a report

Finally, convert the test results into an HTML report. This can be done by one of two commands:

- `allure generate` processes the test results and saves an HTML report into the `allure-report` directory. To view the report, use the `allure open` command.

- `allure serve` creates the same report as `allure generate`, then automatically opens the main page of the report in a web browser.

## Writing tests

The Allure Cucumber.rb integration extends the standard reporting features of Cucumber.rb by providing additional capabilities for crafting more informative and structured tests. This section highlights key enhancements that can be utilized:

- **Metadata Annotation**: Enhance test reports with [descriptions, links, and other metadata](#adding-metadata).
- **Test Organization**: Structure your tests into clear hierarchies for better readability and organization [organize tests](#organize-tests).
- **Step Division**: Break down tests into smaller [test steps](#divide-a-test-into-steps) for easier understanding and maintenance.
- **Parametrized Tests**: Clearly describe the parameters for [parametrized tests](#describe-parametrized-tests) to specify different scenarios.
- **Attachments**: Automatically capture [screenshots and other files](#attach-screenshots-and-other-files) during test execution.
- **Test Selection**: Use a test plan file to [select which tests to run](#select-tests-via-a-test-plan-file), allowing for flexible test execution.
- **Environment Details**: Include comprehensive [environment information](#environment-information) to accompany the test report.

### Adding Metadata

Allure allows you to enrich your reports with a variety of [metadata](/docs/v2/readability/#description-links-and-other-metadata). This additional information provides context and details for each test, enhancing the report's usefulness. Refer to the [metadata reference section](/docs/cucumberrb-reference/#metadata) for an exhaustive list of what can be added.

```ruby
require 'allure-cucumber'

When 'I open labels page' do
  Allure.description_html 'This test attempts to log into the website using a login and a password.'
  Allure.label 'owner', 'John Doe'
  # ...
end
```

### Organize tests

As described in [Improving navigation in your test report](/docs/v2/navigation/), Allure supports multiple ways to organize tests into hierarchical structures.

To specify a test's location in the [behavior-based hierarchy](/docs/v2/navigation/#behavior-based-hierarchy):

**Runtime API:**
```ruby
require 'allure-cucumber'

When 'I open labels page' do
  Allure.epic 'Web interface'
  Allure.feature 'Essential features'
  Allure.story 'Authentication'
  # ...
end
```

**Gherkin tags:**
```gherkin
Feature: Labels

  @EPIC:WebInterface
  @FEATURE:EssentialFeatures
  @STORY:Authentication
  Scenario: Create new label for authorized user
    When I open labels page
    And I create label with title "hello"
    Then I should see label with title "hello"
```

To specify a test's location in the [suite-based hierarchy](/docs/v2/navigation/#suite-based-hierarchy):

```ruby
require 'allure-cucumber'

When 'I open labels page' do
    Allure.label 'parentSuite' 'Web interface'
    Allure.suite 'Essential features'
    Allure.label 'subSuite', 'Authentication'
  # ...
end
```

### Divide a test into steps

Allure Cucumber.rb provides three ways of [creating steps and sub-steps](/docs/steps/): “annotated steps”, “block-based steps” and “no-op steps”, see the [reference](/docs/cucumberrb-reference/#test-steps).

**Annotated steps:**
```ruby
require 'allure-cucumber'

When 'I open labels page' do
  Steps.step_1
  Steps.step_2
end

class Steps
  extend AllureStepAnnotation

  step 'Step 1'

  def self.step_1
    step_1_1
    step_1_2
  end

  step 'Step 1.1'

  def self.step_1_1
    # ...
  end

  step 'Step 1.2'

  def self.step_1_2
    # ...
  end

  step 'Step 2'

  def self.step_2
    step_2_1
    step_2_2
  end

  step 'Step 2.1'

  def self.step_2_1
    # ...
  end

  step 'Step 2.2'

  def self.step_2_2
    # ...
  end
end
```

**Block-based steps and no-op steps:**
```ruby
require 'allure-cucumber'

When 'I open labels page' do
  Allure.run_step 'Step 1' do

    # ...
    Allure.step name: 'Step 1.1', status: :passed

    # ...
    Allure.step name: 'Step 1.2', status: :passed
  end

  Allure.run_step 'Step 2' do

    # ...
    Allure.step name: 'Step 2.1', status: :passed

    # ...
    Allure.step name: 'Step 2.2', status: :passed
  end
end
```

### Describe parametrized tests

An Allure test report can reflect two ways in which you can pass data from your Gherkin file to your Ruby implementation code, namely:

- [scenario outlines](/docs/cucumberrb-reference/#scenario-outlines),
- [runtime parameters](/docs/cucumberrb-reference/#runtime-parameters).

The example below shows a Gherkin file and a Ruby implementation file of a test. In this example, the four parameters for the “I enter my details...” step will be displayed in both instances of the scenario in the test report.

```gherkin
Feature: User management

  Scenario Outline: Registration
    When I go to the registration form
    And I enter my details: <login>, <password>, <name>, <birthday>
    Then the profile should be created

    Examples:
      | login   | password | name     | birthday   |
      | johndoe | qwerty   | John Doe | 1970-01-01 |
      | janedoe | 123456   | Jane Doe | 1111-11-11 |
```

```ruby
require 'allure-cucumber'

When 'I go to the registration form' do
  # ...
end

And /^I enter my details: (.*), (.*), (.*), (.*)$/ do |login, password, name, birthday|
  # ...
end

Then 'the profile should be created' do
  # ...
end
```

### Attach screenshots and other files

In Allure reports, you have the ability to [attach various types of files](/docs/attachments/), which can greatly enhance the comprehensibility of the report. A common practice is to attach screenshots that capture the state of the user interface at specific moments during test execution.

For detailed instructions on how to implement attachments, refer to the [attachments section in the Allure Cucumber.rb reference](/docs/cucumberrb-reference/#attachments).

```ruby
require 'allure-cucumber'

When 'I open labels page' do
  Allure.add_attachment name: 'Screenshot',
                        source: File.new('/path/to/image.png'),
                        type: Allure::ContentType::PNG
  Allure.add_attachment name: 'Data',
                        source: 'This is the file content.',
                        type: Allure::ContentType::TXT
  # ...
end
```

### Select tests via a test plan file

If the `ALLURE_TESTPLAN_PATH` environment variable is defined and points to an existing file, Cucumber.rb will only run tests listed in this file.

Here's an example of running tests according to a file named `testplan.json`:

**MacOS/Linux:**
```bash
export ALLURE_TESTPLAN_PATH=testplan.json
bundle exec cucumber
```

**Windows:**
```plain
setx ALLURE_TESTPLAN_PATH "testplan.json"
bundle exec cucumber
```

### Environment information

For the main page of the report, you can collect various information about the environment in which the tests were executed. To do so, specify the information in the [`environment_properties`](/docs/cucumberrb-configuration/#environment-properties) configuration parameter.

For example, it is a good idea to use this to remember the OS version and Ruby version. This may help the future reader investigate bugs that are reproducible only in some environments.

Images: /images/ruby/environment-allure3.png, /images/ruby/environment-allure2.png

```ruby
require 'allure-cucumber'

AllureCucumber.configure do |config|
  config.environment_properties = {
    os_platform: RbConfig::CONFIG['host_os'],
    ruby_version: RUBY_VERSION,
  }
end
```

Note that if your launch includes multiple Cucumber.rb runs (see [How it works](/docs/how-it-works/)), Allure Cucumber.rb will only save the environment information from the latest run.
