Skip to content

Archive for

9
Apr

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.
3039EF3C-29B0-4158-811A-AB81ED1EC42A
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:
3E31D88F-B5DA-48EF-84A2-52B6128A59EB
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 serenity.properties file:
serenity.requirement.types = epic, feature
This would produce epics rather than capabilities in the requirements report:
DB980BC9-365A-48E3-BB31-24CC5903C62D
Now suppose you wanted to add a “theme” level above the epics and features. You could organise the features directory like this:
0AC724A3-4EF6-42DB-81D4-890FF6E53DBE
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:
@version: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.
@version:Release-1
@version:Sprint-1.1
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:
E9F98098-0217-4A73-8503-653A57EB0A49
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 serenity.properties file:
serenity.release.types = Version,Iteration