Skip to content
Swarmetry

Build scenarios

Browser journeys

Find elements the way users see them, work inside frames, wait and check in browser steps.

Load tests with real browsers are not included in the plans for now. A scenario keeps its browser steps, but its test runs, debug runs, preflights and schedules are refused, and the workflow editor says so. Browser steps still run in the browser checks of monitoring.

A browser step drives a real browser the way a person does: it opens pages, clicks, types and checks what the page shows. This page explains how to point at the right element, how to work inside frames, and how to wait and check at the right moment, without writing code.

Find elements the way people see them

Select a browser step in the workflow editor. Under Element, first choose how to find the element, then fill in its fields. A sentence under the fields says what the step will find, for example Finds the button named “Add to cart”.

Finding an element

Find the element When Example
The button, link or field named… buttons, links, check boxes, fields, headings… by the name people see or hear: the most robust choice the button “Add to cart”
The field labelled… a form field with a label the field labelled “Email address”
The text… a text shown on the page the text “Welcome back”
The field showing the hint… a field named by the grey hint shown while it is empty “Search the lab”
The image described as… an image, by its alternative text “Company logo”
The element with the tooltip… an element that shows a tooltip “Order status”
The element with test id… an element the developers marked for tests (data-testid) cart
A CSS selector, an XPath expression (advanced) when nothing above fits #cart > li

Good to know:

  • By default a part of the text is enough and capitals do not matter: “Add” finds “Add to cart”. Tick The whole text, same capitals to require the exact text.
  • Tick Regular expression to describe a pattern, for example ^Order #[0-9]+$. A pattern cannot contain a variable.
  • Names and texts can use variables: type two opening braces {{ and pick one. They cannot use a secret: the text searched for appears in error messages and logs.
  • When several elements match, the step uses the first one. Under When several elements match, choose Use the last or Use the n-th and give its position (1 is the first).
  • A step created earlier, or by an import, with a selector opens as a CSS or XPath selector. Choose another kind to replace it: a step keeps one way to find its element, never two.

Elements inside a frame

Some pages show a part of their content in a frame (an iframe): a payment form, a chat window, an embedded map. Open Inside a frame…, add the frame and give the selector of the iframe, for example #checkout or iframe[name="card"]. For a frame inside another frame, add both, the outer one first (up to five).

An element inside a frame

Actions

Action What it does
Open a page goes to an address (a path such as /login uses the base address of the scenario)
Go back, Go forward, Reload the page the buttons of the browser
Click, Double-click, Hover act on the element with the mouse
Fill puts a value in a field at once
Type key by key types like a person, with a pause between keys (50 to 150 ms looks natural): use it for fields that react to each key, such as a search with suggestions
Clear a field empties a field
Select an option, Check, Uncheck lists, check boxes and radio buttons
Press a key Enter, Tab, Escape… on an element, or on the page
Read a text saves the text of an element in a variable for later steps
Take a screenshot saves a picture of the page

Wait for the right moment

Actions wait by themselves for their element, up to their timeout (30 seconds by default). Add a wait when the page needs time for something else:

Wait Use it when
Wait for an element an element must appear
Wait for an address the address changes after a click; choose Contains to give only a part of it, such as /account
Wait for the page to load a page must finish loading
Wait for a response the page must receive the answer of a request; give the expected status (for example 200) to check it

Waiting for an address

When an action triggers the request you wait for (a click that loads a list, a search typed key by key), open Wait for a response of this action… in that step instead of adding a separate wait: the wait then starts just before the action, so a fast response is never missed. Give a part of the address of that response (the field starts empty and is flagged until you fill it). Swarmetry warns you when a separate wait for a response follows an action, and its quick fix moves the wait into the action.

Waiting for a response of an action

Avoid The network is idle: on a page that keeps exchanging data, the network is never idle and the step fails at its timeout (Swarmetry shows a note). After Go back or Go forward, the browser often shows the page it kept in memory without loading it again: a wait for its address or its loading that follows then ends at once.

Check what the page shows

Checks are retried until they hold or their timeout runs out (5 seconds by default), so a page that is still updating does not make them fail. Each check appears in the results under its name: the name of the step, or what it checks, such as url contains /account.

Check What it checks
Expect a text the text of an element contains, is exactly, or matches a pattern
Expect visible, Expect hidden the element is shown or not
Expect enabled, Expect disabled a button or a field can be used or not
Expect checked, Expect unchecked a check box or a radio button
Expect a field value what a field holds (an empty value checks that it is empty)
Expect an attribute an attribute of an element, such as the address of a link, or only that it exists
Expect a number of elements how many elements match: at least, exactly, at most, more than or fewer than a number
Expect an address, Expect a page title the address or the title of the page

Expecting a number of elements

A failed check marks the step as failed in a debug run and lowers the rate of successful checks of the test, which your thresholds can judge (Test configuration).

Recorded journeys

When you turn a recording into a browser scenario (Scenarios), Swarmetry finds each element the same way: by its test id, else its role and name, its label, its hint, the visible text of a button or a link, and a CSS selector only when nothing else exists. A name, a label, a hint or a text is used only when no other element of the page shares it; otherwise the element keeps its id or its CSS selector. An element inside a frame keeps its frames.

With the assistant, the CLI or the API

Everything above is part of the scenario (the locator of a browser step and its actions). The assistant knows worked examples of locators, actions and checks, and finds elements by role and name like the editor does. Ask it, for example: “in the scenario Checkout, click the button named Pay inside the frame #payment, then expect the text Thank you”.