Writing gherkin test cases in cucumber
Feature contents
Below there is an example of a feature file.
The document starts off with <yellow>Feature</yellow> : following with the <turquoise>title of the feature</turquoise> . It's a common rule to have the same file name as the feature title.
After the title, the <gray>description</gray> follows. This is a free text starting on a new line. At this part you can make a small summary of what the feature file contains.
After this you can follow with <green>one or more Scenarios</green> with a <pink>name</pink> .
Scenario contents
The texts " <yellow>Given, And, When, Then</yellow> " are all used to make it readable. However, Cucumber does expect one of these words before every <turquoise>step</turquoise> to recognize the beginning of a new <turquoise>step</turquoise> .
Scenario outline contents
Sometime you want to use different data for the same scenario. This can be done with a so called Scenario Outline.
You can create a
<yellow>scenario outline</yellow>
the same way as a regular scenario, write Scenario Outline:
followed by the name of
the scenario.
After writing the steps for the scenario you can write
<gray>Scenarios:</gray>
followed by a new line.
Now you can create a grid/table, by using |. The first row of this table will represent the <turquoise>variable names</turquoise> . Every following row will be the <green>variable value</green> for that specific scenario. (Result in the first scenario is 120 and in the second it is 20).
Now you can use the variable value in your steps by using <variablename>. So in this example, the 4th step in the 2nd run will be:
Then the result should be 20 on the screen.
Tags
Tags allow you to group or individually select scenarios or features for running. We will be actually running the features in the next article.
Running with the @calculator
tag executes the entire feature.
Running with either of the @addition
or @subtraction
tag only executes one scenario each.
You can also run with @calculator ~@subtraction
to de-select subtraction tests