Allure Cucumber.rb

Allure Cucumber.rb gem latest version

Generate beautiful HTML reports using Allure Report and your Cucumber.rb tests.

Allure Report Cucumber.rb Example

Check out the example project at github.com/allure-examples/allure-cucumber-example to see Allure Cucumber.rb in action.

How to start

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.

  2. 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'
  3. Open a terminal, go to the project directory and install the dependencies from the Gemfile. For example, if you use Bundler:

    Bash
    cd /home/user/myproject bundle install
  4. In the project's cucumber.yml 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. 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, run Allure to convert the test results into an HTML report. This will automatically open your browser to view the report.

Bash
allure serve allure-results

If necessary, replace allure-results with the path to the directory specified in the Configuration.

There are some options that can affect how the report is generated. Run allure --help for the full list of options.

Writing tests

The Allure Cucumber.rb adapter 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:

Adding Metadata

Allure allows you to enrich your reports with a variety of metadata. This additional information provides context and details for each test, enhancing the report's usefulness. Refer to the metadata reference section 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, Allure supports multiple ways to organize tests into hierarchical structures.

To specify a test's location in the behavior-based hierarchy:

Ruby
require 'allure-cucumber' When 'I open labels page' do Allure.epic 'Web interface' Allure.feature 'Essential features' Allure.story 'Authentication' # ... end
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:

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: “annotated steps”, “block-based steps” and “no-op steps”, see the reference.

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
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:

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, 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.

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:

Bash
export ALLURE_TESTPLAN_PATH=testplan.json bundle exec cucumber
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 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.

Allure Report Environments Widget

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), Allure Cucumber.rb will only save the environment information from the latest run.

Powered by
logo

Join our newsletter

Join our community

We aim to make Allure Report as reliable and user-friendly as possible, and together with the community, we're here to help when problems arise.

© 2024 Qameta Software Inc. All rights reserved.