Writing tests
How the step editor works, including selectors, optional steps and step conditions.
Steps
Steps run top to bottom. Each step has buttons to add a step above or below, move it up or down, duplicate it or remove it. Each action has its own fields, documented on its reference page.
Selectors
Element fields accept CSS selectors or XPath. A selector is treated as XPath when it starts with /, ./, ../ or ( , or with an XPath axis such as ancestor::. Prefix a selector with xpath= or css= to choose the type explicitly.
A step can also hold several alternative selectors. Each one is tried in turn until an element matches, within the suite's Element Timeout.
Prefer ids and data-test attributes. Generated class names and long positional paths break when the page changes. The Selectors guide covers this in more detail.
#login-button
[data-test='cart-total']
//button[normalize-space()='Place order']
xpath=(//a[@class='product'])[1]Optional steps
Tick Make this step optional (Continue on failure) to let the test continue when the step fails. Use it for cookie banners and other elements that do not always appear.
The option is available on every action except Set variable.
Step conditions
Select Add condition on a step to show the field Execute step when JavaScript returns true:. The code runs in the page before the step. A new condition starts as false, so replace it with your own check.
If the code returns a falsy value, the step is skipped and counts as passing. If the code throws an error, the step fails. Conditions are not available on HTTP request steps. The Conditional steps guide has more examples.
return document.querySelector('#promo-dialog') !== null;Descriptions
Mouse and keyboard steps have a Description (Optional) field. It is exported as a comment in Gherkin and Playwright code.