Skip to content

Write the Script of a Gherkin Test Case

A Gherkin test case's consultation page is different because of the structure of its Ancre ScriptScript page. This page offers a specific text editor with syntax highlighting and verification, without autocompletion.

Ancre Script d'un cas de test de Gherkin

In Squash TM, a Gherkin test case can be executed manually as a classic test case, or exported for an external automated execution.

Gherkin Test Case Script

The Gherkin script language is defined by the language tag in the first line of the script: #language: < local >. You can change the script's language by replacing < local > by the two letters representing the user's language.

  • fr for French
  • en for English
  • es for Spanish
  • de for German

For the script's language to be taken into account, the language tag must be in accordance with the Gherkin specifications and be placed first in the script. The keyword "Feature" must also be translated into the desired language. If the tag is missing or invalid, Squash TM will interpret the script as written in English.

The second line contains the keyword "Feature", followed by the name of the test case.

The scenario must be written with the following syntax:

  • Scenario followed by the name of the test scenario or Scenario Outline followed by the name of the test scenario with datasets

  • Given followed by the context in which the test must be done

  • When followed by the action to be done by the user

  • Then followed by what is expected as a result of the action

  • Examples followed by a data table containing the datasets of a scenario plan

You can also add further instructions by using keywords indicating a continuation such as and* or but**.

Learn More

To learn more about how to variabilize a Gherkin scenario, please visit the page Variabilize a Gherkin script

By clicking on the script's text field, it becomes white and editable. Several buttons appear on top of the script, which enable you to:

  • Confirm the changes made. You can also save them by using the keyboard shortcut [CTRL]+[ALT]+[S]

  • Cancel the changes made since the last save and switch back to read-only mode

  • Insert snippets in the script

  • Check the script's syntax

Gherkin Test Case Script

Focus

If the user does not have the permission to modify the test case, or if one of the milestones linked to the test case has a "locked" status, the script cannot be edited.

Insert Snippets

Snippets are reusable code templates that you can insert in the script editor via the button Insérer to save time during the writing.

In Squash TM, the snippets available are:

  • param inserts <> for the notation of parameters
  • sc inserts a scenario with the keywords Scenario, Given, When, Then
  • scout inserts a scenario with the keywords Scenario outline, Given, When, Then, Examples
  • tab4*3, tab4*2, tab3*3, tab3*2 inserts data tables whose number of columns and lines is indicated in their name. A heading row is also added

Insert snippets in a Gherkin script

Check the Script's Syntax

When the text field is in editing mode, the button Check enables you to check that the Gherkin syntax is correct before confirming the changes.

If the script is invalid, a popup appears with an error message from the Gherkin parser.

Check the script's syntax

Help

On a Gherkin test case's consultation page, the button Aide displays a couple of writing tools:

  • a glossary of keywords

  • examples of different test scenarios for different features

The help is displayed on the right of the Gherkin script in the same language as the one defined for the script.

Aide à la rédaction des cas de test Gherkin