| title | Dynamic Locators using Parameter | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| page_title | Dynamic Locators using Parameter: Enhance Test Stability | ||||||||||||||||||||||||||||||||||||||||
| metadesc | This article discusses the usage of Parameter Test Data for creating dynamic locators to use in Data-driven Testing | Learn about Parameter Test Data | ||||||||||||||||||||||||||||||||||||||||
| noindex | false | ||||||||||||||||||||||||||||||||||||||||
| order | 6.81 | ||||||||||||||||||||||||||||||||||||||||
| page_id | dynamic-locators-using-parameter-in-testsigma | ||||||||||||||||||||||||||||||||||||||||
| warning | false | ||||||||||||||||||||||||||||||||||||||||
| contextual_links |
|
Dynamic locators are necessary for data-driven testing because they help adjust to changes in elements. You can use a Test Data profile to set the variable part of the ID attribute. The parameter name, called elements, holds the dynamic data for storing the dynamic part. Testsigma makes this easy using parameterised XPath or CSS Selectors in test steps. This guide will show you how with a practical example.
Prerequisites
Before you begin, ensure that:
We are using the Simply Travel Flight website as an example and sorting the city names and the variable part of the element's ID attribute in the test data profile.
-
Navigate to the website containing the elements you want to copy the XPath.
-
We will use the Simply Travel Flight website as an example of the above test steps. Click Select from Cities and copy the XPath values for the cities.
-
Right-click on the desired and select Inspect to open Chrome Developer Tools.
-
Use the Select Element icon to locate and inspect the element, then right-click the HTML tag and copy the XPath.
-
The table below explains how the city names and their corresponding XPath for an element.
Cities XPath Los Angeles //*[@id="city-1"]/div[2]/span[1]Washington, D.C. //*[@id="city-2"]/div[2]/span[1]New York City //*[@id="city-3"]/div[2]/span[1]London //*[@id="city-4"]/div[2]/span[1]-
In the provided XPath examples, the IDs of the cities have a common portion, city-, followed by a variable digit from 1 to 4. We will parameterise this by storing the city and the variable portion using a Test Data profile.
-
Navigate to Test Data > Test Data Profile. Click on Create Test Data Profile.
-
Below is the created Test Data profile for storing element ID attributes:
-
Use NLP to create a new step in the Test Case and include a placeholder for the element.
[[info | Example:]] | Utilise NLP "Click on Element" to click an element with a given UI Identifier.
-
Click on the Element, then select Create Element from the dropdown list.
-
Manually enter the Element Name, Screen Name, and Element Type in the Create Element overlay screen.
-
Provide the dynamic element value //*[@id="@|cities|"]/div[2]/span[1], where cities is the parameter name containing dynamic data.
-
Click Create Element to complete element creation and then Create Step.
-
In Test Case details page, click Test Case Settings in the right-side navbar.
-
Enable the Data-Driven toggle and select Filter Type, Comparison Metric, and Data Iteration.
-
Once the test step created with the dynamic Element, execute the Test Case.
-
Wait until the Test Case execution is completed.
-
The Test Case will iterate as many times as there are Test Data Sets (rows) in the Test Data Profile, resulting in four iterations based on the provided example.
-














