Skip to content

Archive for


Customizing Cucumber Feature File organization with Serenity

Many Cucumber projects organize their feature files in a single directory. This flat structure will work for very small projects, but in real-world project features typically need to be grouped by more high-level concepts, such as capabilities or epics. Serenity BDD makes this very easy
By default, Serenity uses a two-level hierarchy based on capabilities and features. A capability is represented by a directory, and the features associated with that capability are placed inside that directory.
If you use a directory structure like this, the “Requirements” tab in the Serenity reports will display a hierarchy of capabilities and features, and aggregate test results for each capability and feature:
We can customize the hierarchy using the serenity.requirement.types system property. If we wanted epics instead of capabilities, we could add the following line to our file:
serenity.requirement.types = epic, feature
This would produce epics rather than capabilities in the requirements report:
Now suppose you wanted to add a “theme” level above the epics and features. You could organise the features directory like this:
Then you would configure the serenity.requirement.types property as shown here:
serenity.requirement.types = theme, epic, feature
This would add a “Themes” requirements level above your epics in the Requirements reports.
You can also organize your features into releases, iterations, or sprints. You do this using the version tag. For example, the following feature would be scheduled for Release-2:
Feature: Search by keyword
  In order for buyers to find what they are looking for more efficiently
  As a seller
  I want buyers to be able to search for articles by keywords

  Scenario: Search for articles by keyword
    Given I want to buy a wool scarf
    When I search for 'wool'
    Then I should see only articles related to 'wool'
(Note that Cucumber does not like spaces in tags, so you need to write “Release-2” and not “Release 2”).
You can also assign a feature to both a release and a sprint, e.g.
Feature: Add item to shopping cart
  As a buyer
  I want to be able to purchase items online
  So that I can get them faster

  Scenario: Add item to cart
    Given I have searched for 'docking station'
    And I have selected item 2
    When I add it to the cart
    Then the item should appear in the cart
    And the shipping cost should be included in the total price
This will produce a “Releases” tab in the reports, similar to the following:
You can tell Serenity what terms your release organisation uses (e.g. releases then sprints or releases then iterations) using the serenity.release.types system property. For example, if you wanted to use versions, then iterations, you would put the following line in your file:
serenity.release.types = Version,Iteration