Does anyone know of a way to achieve this or do they think it's a good idea. To have an OR style syntax in Gherkin for reducing repetition but maintaining human readability (hopefully). I'm thinking of cases where clause combinations are expanded with every combination of multiple OR statements. e.g.
Scenario: TestCopy
Given Some text is selected
When The user presses Ctrl + C
OR the user right clicks and selects copy
OR the user selects Edit + Copy
Then the text is copied to the clipboard
This would run as 3 tests each with the same given and then but with one When from the OR set. I guess this could have been acheived using a template with a place holder for the When clause but I think this is more readable and could allow the OR to be used in the Given as well to produce n x m tests. With the outline you would still need n x m rows.
Thanks.
This syntax promotes behavior-driven development because it allows developers, managers, business analysts and other parties involved to understand the requirements of the project and the life-cycle. The language makes it easy to create simple documentation of the code that's being written.
Gherkin is part of the Cucumber framework for BDD, which aims to create a testing framework in easily readable language based on a few keywords.
Gherkin Syntax - Cucumber Documentation.
Gherkin is Cucumber's language parser, which allows software behaviours to be specified in a logical language that people can understand. This means that Cucumber feature documentation is written in business-facing text that is non-technical and human readable for stakeholders like business analysts and managers.
You can generatd multiple tests from one scenario with Scenario Outlines:
Scenario Outline: TestCopy
Given Some text is selected
When <Copy operation executed>
Then the text is copied to the clipboard
Examples:
| Copy operation executed |
| The user presses Ctrl + C |
| the user right clicks and selects copy |
| the user selects Edit + Copy |
In a Scenario Outline
you basically create a template which is filled in the with the provided Examples
.
For the the above example Specflow will generate 3 tests with the same Given
and Then
and with the 3 different When
s:
When The user presses Ctrl + C
When the user right clicks and selects copy
When the user selects Edit + Copy
It's not recommended to use this detail level (pressing these keys, right clicking) on the scenarios. This makes them, as you realize, lengthy and repetitive. Also, that's usually not the information the stakeholders would need or want anyway.
The best would be to hide the implementation details on the step definitions. Your scenario would be something like:
Scenario: TestCopy
Given some text is selected
When the user copies the selected text
Then the selected text is copied to the clipboard
And the different ways of copying the text would go to the 3rd step definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With