Variables
Minimize hardcoding to reuse test data across multiple steps
Variables are useful when a value input during test recording needs to be reused later within the same test. It helps in:
- Eliminating hardcoded values
- Maintaining tests easily. You can update the variable at one place rather than modifying it across multiple test steps.
- Making tests more readable and self-explanatory by assigning meaningful names.
When to use variables?
- Use variables when dealing with repeated static values across different steps within a test. For example:
- Validate full name or email in accounts profile section after logging in
- Validate pricing details on checkout page after selecting a particular plan
-
When the test requires dynamic input that may change during each test run which has to be consumed at a later point in the test.
- Use variables to centralize and manage data to make tests easier to update and maintain.
How to create and use a variable?
There are four ways to create variables:
- Define static variables for test steps: Create a variable at any step where you have to input values.
- Extract value from website dynamically: Capture dynamic values from website UI and store them as variables for later use.
- Create variables using Custom JS script: Use javascript snippet to create variable from more advanced workflows. For more information, see Configure custom actions using Javascript.
- Extract value from API response: Store the response details from API step into a variable for later use. For more information, see Extract value from response.
You can reuse these variables anytime you need to input values or perform text validation.
Define variables for test steps
- Navigate to the step where you have an input value which has to be reused.
- Click on the step name or the “>” icon to open the step configuration details.
- Click on “Convert to variable” below the text input.
- Give a unique meaningful name to the variable and save it.
Extract value from website dynamically
In test automation, there could be scenarios where you would want to store some text content on the UI which dynamically changes into a variable. The Extract Value feature lets you capture these dynamic values from screen elements, store them as variables and reuse them in your test. For example, you can capture the price_of_product
and store it in a variable to validate in checkout page if the total cost equals price_of_product
* quantity
. Since the price_of_product
may change, extract value lets you use the updated values for a reliable test execution.
Perform the following steps to capture dynamic values from screen elements during test execution:
- In the recorder, click the Ellipsis icon and select Extract Value.
- Hover over the screen and select the element to create variable. For example, you can select a product price.
- In the Save extracted value dialog, assign a name to the variable.
- Select one of the following options under Extracted value:
-
Entire text: Captures the full content of the element. For example, you can capture
Price: $22
and store it in the variableproduct_price
. -
Filter specific text: Extracts specific text using a regular expression. For example, you can use a Regex like
\d+\.\d{2}
to capture only the price. This will extract just199.99
from the stringPrice: $199.99
, excluding the currency symbol and the word “Price”.
-
Entire text: Captures the full content of the element. For example, you can capture
- Click Create.
For more details on regex and advanced patterns, refer to the Regular Expressions and Regex cheat sheet document.
Importing a variable
- Navigate to the step where you want to reuse the variable created.
- Click the step name or the > icon to open the step configuration details.
- If the step is an input step, click the + and select Import a variable. If the step is a text validation step, click the {} icon besides the text input.
-
Import variable in Input step
-
Import variable in Text validation step
-
Import variable in Input step
- Select the relevant variable you want to import.
Managing a variable
- Managing a variable is possible at any step where the variable is in use. You can navigate to the step configuration details and edit the variable to any value of your choice.
- Additionally, Low Code Automation also allows you to manage your variables from a single configuration page where you can edit any variable value and delete any variable that is not in use. Click on the “⚙” icon to access the page.
- A variable can only be deleted when it is not used in any other steps.
- A variable can not have a variable within it.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!