Dynamic Selectors
Last updated
Dynamic Selectors make automated tests more resilient by allowing selectors to use variables instead of fixed values.
This is useful when applications display dynamically generated content such as project names, customer names, order numbers, or other data that changes between test runs.
Instead of locating an element using a fixed value:
Then "Project Demo123" is displayedyou can reference a variable:
Then "Project {{projectName}}" is displayedAt runtime, TestFirst automatically replaces the variable with its current value before locating the element.
Dynamic Selectors can be created while recording a test.
Start Recording a test in the TestFirst Editor. The Recorder toolbar appears.
Right-click the action you want to record (for example, Click or Validate).
Select Dynamic selector.
Click the target element in the application.
TestFirst records the action using a variable-aware selector instead of a fixed value.
Tip: The Validate action records a Then "..." is displayed assertion. Right-click Validate and select Dynamic selector to create a dynamic validation.
If you want to bind the selector to an existing variable:
Add a variable assignment before the recorded action, for example:
Run the test up to that step so the variable is available in the current recording session.
Record the Dynamic Selector as described above.
TestFirst uses the variable value when creating the selector, allowing the same test to work with different application data.
Dynamic Selectors work with AI-generated element descriptions on web applications.
When the Recorder detects dynamic values, it can generate selectors that use variables, making recorded tests more resilient to changing application data.
The same test can now run repeatedly without updating selectors when the project name changes.
Dynamic Selectors reduce maintenance by making automated tests resilient to dynamically generated application data.
Last updated
When I set "projectName" variable to "Project Alpha"Scenario: Create a project
When I type "Project-{{random value}}" in "Project name"
And I click "Create"
Then "Project-{{random value}}" is displayed
