In the Gherkin editor, you can view and edit BDD test scenarios.
Open the editor
-
Switch to the Project Explorer panel (if it is hidden, select View > Project Explorer from the main menu of TestComplete).
-
Double-click any child node (feature node) of the Scenarios project item. TestComplete will open the editor in the Workspace panel:
Editor contents
Here is a sample view of the editor:
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 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:
– or –
-
Right-click the test step and select Go to Definition from the context menu:
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.
-
Quick indentation. This is helpful when you need to align test steps quickly.
-
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):
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):
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:
Toolbar
Item | Description |
---|---|
Run This FeatureScenario, or |
The action depends on the position of the insertion point in the Gherkin editor:
|
Generate Step Definitions |
Generates script functions for The item is disabled if the feature, scenario or test step descriptions violate the Gherkin syntax. |
Decrease Indent and |
Change the indent of the current line or block of code. |
Hide Selected Lines and |
Collapse the selected block of text or expand a collapsed block. See Outlining. |
Navigate Back and |
Switch between previous and more recent locations of the insertion point. |
Panel Options |
Opens a dialog box with editor options. |