Search:

Simplify Cucumber Scenarios

Simplify Cucumber Steps

Cucumber is a testing tool which is using Behavior Driven Development approach. It helps test engineer to develop scenarios with Gherkin syntax easily. However, in the later stages of the project, code complexity is increased depending on development.

The following tips could be used to reduce maintenance cost and complexity, have better project structure.

1-Background

The scenarios in a feature file usually start with the same steps. Do not repeat these common steps in each scenario, gather the steps under background to prevent the repeat.

Screen Shot 2019-03-21 at 11.14.41

Using Background option in the feature file gathers the common steps at the top of the file and prevents to repeat the same steps for each scenario.

Screen Shot 2019-03-21 at 11.16.17

 

2- Scenario Outline

If you want to run a scenario with a dataset, use "Scenario Outline" instead of "Scenario".

 Screen Shot 2019-03-21 at 11.16.17

Using “Scenario Outline” provides more readable feature files as you see below.

Screen Shot 2019-03-21 at 11.18.24

 

3- Combine Steps in a Step

It is possible to group step definitions and create higher-level step definitions. It helps to reduce extra lines in feature files, like previous sections, making it easier to read.

Screen Shot 2019-03-21 at 11.19.26

Screen Shot 2019-03-21 at 11.20.13

4- Table structure

Although it seems like the Scenario Outline structure at the beginning; the data sets of the data repeat itself only for this step. If the Scenario is Outline, Scenario works as much as the number of data. If it is in the Table structure, the corresponding step repeats itself as much as the number of data defined, but the whole of our scenario runs once.

Screen Shot 2019-03-21 at 11.38.33

 

Cucumber makes scenario development easier thanks to its advantages.
If you use Cucumber’s useful features which mentioned above, your feature files will be more readable and efficient. Beside, these features make maintaining easy for each team member.

Ali Fuat Ateş

Junior Test Automation Consultant at kloia

Want to work with us?

We embrace a free working culture. You are free to contribute to kloia on the beach with a fresh beverage, in an isolated secret remote treehouse, at the client site, or from a co-working office.

Contact us