The Statements category contains the following test actions.
The Define Element Selector action allows you to create an element selector that identifies a webpage element.
To create an element selector:
Specify the element selector's name in the Name field.
Selector names must be unique in a test. You also cannot use the following reserved words: t, fixture, test, Selector, ClientFunction, RequestLogger, RequestMock, RequestHook.
Use the element selector constructor to define the element selector.
You can use the created element selectors in on-page actions and assertions. The main benefits are:
The element selector's short name makes tests easier to read.
You can define an element selector once and use it in several test actions. If the tested webpage changes, you need to edit the element selector in the Define Element Selector action, but do not need to edit other actions. This makes your tests easier to maintain.
The Define Function action allows you to create a function that returns data from the tested webpage. You can then verify this data in assertions.
This type of function cannot return non-serializable objects (DOM elements,
window, etc.). Use element selectors instead.
To create a function:
Specify the funсtion's name in the Name field.
Function names must be unique in a test. You also cannot use the following reserved words: t, fixture, test, Selector, ClientFunction, RequestLogger, RequestMock, and RequestHook.
Write the code. Use the
return statement to return the desired data.
The following image demonstrates how to define a function that returns the URL of the currently open page.
Then you can verify if the returned URL matches the expected URL using the Deep Equal assertion.
You cannot use generators or
async/await syntax within functions. To run asynchronous code, use a Promise within a function. The function is complete only when this Promise resolves.
You cannot use element selectors within functions.