Gherkin Editor

Applies to TestComplete 15.49, last modified on March 17, 2023

In the Gherkin editor, you can view and edit BDD test scenarios.

Open the editor

  1. Switch to the Project Explorer panel (if it is hidden, select View > Project Explorer from the main menu of TestComplete).

  2. Double-click any child node (feature node) of the Scenarios project item. TestComplete will open the editor in the Workspace panel:

    Open the Gherkin editor

Editor contents

Here is a sample view of the editor:

Gherkin editor

Click the image to enlarge it.

The feature file starts with the Feature: keyword followed by the feature description. The description can be multiline. The lines should not start with a Gherkin reserved keyword like Given, When, and so on.

Feature typically corresponds to a subsystem or some larger functionality of the tested product. Below the feature description, you have a definition of one or multiple usage Scenarios to test.

The Given, When, and Then lines below Scenario are called test steps. You can automate them with TestComplete. For more information on this, see Create Test Step Scripts.

If needed, you can insert comments (# comment text) into the feature file and add tags to scenarios and features (@tag-name).

For more information on writing scenarios and on Gherkin keywords, see Gherkin Syntax in TestComplete.

Generate script code

To generate script functions for a test step, right-click somewhere within the editor and select Generate Step Definitions from the context menu, or click Generate Step Definitions on the toolbar:

The Generate Test Steps command

Click the image to enlarge it.

The generated code has function definitions and special statements that link script functions to test steps (see Binding Script Functions to Test Steps). The script commands that simulate mouse clicks, keyboard events, and other actions should be created or recorded by QA engineers. For more information on creating these script functions, see Create Test Step Scripts.

If some test step already has a script function linked to it, a new function is not generated. If all the steps have script functions linked to them, the “Generate Step Definitions” item is disabled.

Navigation to script code

To jump to a script function linked to a test step:

  • Simply press Ctrl and click the test step description:

    Jumping to the script function linked to a test step

    – or –

  • Right-click the test step and select Go to Definition from the context menu:

    Jumping to the script function linked to a test step

Other editing features

The features the Gherkin editor offers are similar to the features of the Script editor. The Gherkin editor supports:

  • Outlining. You can collapse and expand text blocks.

    See how it works

  • Quick indentation. This is helpful when you need to align test steps quickly.

    See how it works

  • Smart formatting. Whenever you type a quote, opening bracket or brace, the editor automatically enters another quote, closing bracket or brace.

The Gherkin editor also supports some other features of the Script editor like group undo, automatic indents, and some other.

The Editing settings of the Script editor control the behavior of the Gherkin editor. To view or change these settings, select Tools > Options from the main menu and go to Panels > Code Editor > Editing in the subsequent dialog, or click Panel Options on the Gherkin editor’s toolbar.

Run features, scenarios, and steps

Option 1

To run a scenario, click any line of that scenario, and then click Run this scenario on the toolbar. To run all the scenarios your feature file contains, click the Feature: ... line or any line outside any scenario, and click Run this feature file on the toolbar (the caption of this toolbar item depends on the context):

Running BDD tests from the Gherkin editor

Click the image to enlarge it.

Option 2

To run a feature, scenario or an individual test step, right-click the feature, scenario or test step line and select Run This Feature File, Run This Scenario, or Run This Test Step from the context menu (the menu item’s caption depends on what you’ve clicked):

Running BDD tests from the Gherkin editor

Click the image to enlarge it.

Note that test steps depend on earlier test steps and on the tested application state, and they might fail when running outside their scenario. The same concerns scenarios, because in general, they might depend on earlier scenarios. So, we recommend using these Run ... commands for debugging purposes only. To run your BDD tests on a regular basis, use other means that TestComplete offers.

Option 3

One more way to run BDD tests is to make them test items of your project and run them as part of your project run. To append a scenario to test items, right-click the scenario in the editor and select Add Scenario to Test Items from the context menu:

'Add Scenarios to Test Items' menu item


Item Description

Run This FeatureScenario, or
Run This Scenario

The action depends on the position of the insertion point in the Gherkin editor:

  • If the insertion point is on some scenario line, the button runs this scenario.

  • If the insertion point is outside any scenario (for example, it is on the Feature line), then the button runs all the scenarios the feature file contains.

Generate Step Definitions

Generates script functions for Given, When and Then test steps. See above.

The item is disabled if the feature, scenario or test step descriptions violate the Gherkin syntax.

Decrease Indent and
Increase Indent

Change the indent of the current line or block of code.

Hide Selected Lines and
Stop Hiding Current Block or Selected Lines

Collapse the selected block of text or expand a collapsed block. See Outlining.

Navigate Back and
Navigate Forward

Switch between previous and more recent locations of the insertion point.

Panel Options

Opens a dialog box with editor options.

Further reading

See Also

Behavior-Driven Development (BDD) With TestComplete

Highlight search results