Difference between revisions of "Writing gherkin test cases in cucumber"

From Test Automation Wiki
Jump to: navigation, search
Line 3: Line 3:
 
</div>
 
</div>
  
 +
 +
 +
<h2>Feature contents</h2>
 +
<p>Below there is an example of a feature file.</p>
 +
[[file:feature-example-1.png]]
 +
<p>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.
 +
</p>
 +
<p>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.
 +
</p>
 +
<p>After this you can follow with
 +
    <green>one or more Scenarios</green>
 +
    with a
 +
    <pink>name</pink>
 +
    .
 +
</p>
 +
 +
<h2>Scenario contents</h2>
 +
[[file:feature-example-2.png]]
 +
<p>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>
 +
    .
 +
</p>
 +
 +
<h2>Scenario outline contents</h2>
 +
<p>Sometime you want to use different data for the same scenario. This can be done with a so called Scenario
 +
    Outline.</p>
 +
[[file:feature-example-3.png]]
 +
<p>You can create a
 +
    <yellow>scenario outline</yellow>
 +
    the same way as a regular scenario, write <code>Scenario Outline:</code> followed by the name of
 +
    the scenario.
 +
</p>
 +
<p>After writing the steps for the scenario you can write <code>
 +
    <gray>Scenarios:</gray>
 +
</code> followed by a new line.
 +
</p>
 +
<p>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).
 +
</p>
 +
<p>Now you can use the variable value in your steps by using &lt;variablename&gt;. So in this example, the 4th step in
 +
    the 2nd run will be:</p>
 +
<code>Then the result should be 20 on the screen.</code>
 +
 +
<h2>Tags</h2>
 +
<p>Tags allow you to group or individually select scenarios or features for running. We will be actually running the
 +
    features in the next article.</p>
 +
[[file:feature-example-4.png]]
 +
<p>Running with the <code>@calculator</code> tag executes the entire feature.</p>
 +
<p>Running with either of the <code>@addition</code> or <code>@subtraction</code> tag only executes one scenario each.
 +
</p>
 +
<p>You can also run with <code>@calculator ~@subtraction</code> to de-select subtraction tests</p>
 +
</div></div>
  
  
  
 
[[Category:Web Test Automation Tutorial|4]]
 
[[Category:Web Test Automation Tutorial|4]]

Revision as of 16:03, 22 June 2016


Feature contents

Below there is an example of a feature file.

Error creating thumbnail: Unable to save thumbnail to destination

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

Error creating thumbnail: Unable to save thumbnail to destination

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.

Error creating thumbnail: Unable to save thumbnail to destination

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.

Error creating thumbnail: Unable to save thumbnail to destination

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