Dynamic Locators using Parameter


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 implementing dynamic locators using parameters in Testsigma, ensure familiarity with fundamental concepts such as creating a Test Case, managing Test Steps, handling Test Data Profiles and Parameters, and effectively utilising different Test Data Types.


Store Elements ID attribute into Test Data Profile

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.

  1. Navigate to the website containing the elements you want to copy the XPath.
  2. Right-click on the desired and select Inspect to open Chrome Developer Tools.
  3. Use the Select Element icon to locate and inspect the element, then right-click the HTML tag and copy the XPath.
  4. 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. Copy Xpath for storing
  5. 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]
  6. 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.
  7. Navigate to Test Data > Test Data Profile. Click on Create Test Data Profile. Create TDP for storing element
  8. Below is the created Test Data profile for storing element ID attributes: Sample TDP

Creating Dynamic Elements using Parameter

  1. Use NLP to create a new step in the Test Case and include a placeholder for the element. Select Create Element

    Example:

    Utilise NLP "Click on Element" to click an element with a given UI Identifier.

  2. Click on the Element, then select Create Element from the dropdown list.
  3. Manually enter the Element Name, Screen Name, and Element Type in the Create Element overlay screen.
  4. Provide the dynamic element value //*[@id="@|cities|"]/div[2]/span[1], where cities is the parameter name containing dynamic data.
  5. Click Create Element to complete element creation and then Create Step. Create Dynamic ELement using Parameter

Configuring Test Data Profile in Test Case

  1. In Test Case details page, click Test Case Settings in the right-side navbar.
  2. Choose the associated Test Data Profile.
  3. Enable the Data-Driven toggle and select Filter Type, Comparison Metric, and Data Iteration. Config TDP in test case

Run Results for Dynamic Elements using Parameter

  1. Once the test step created with the dynamic Element, execute the Test Case.
  2. Wait until the Test Case execution is completed.
  3. 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. Results for Dynamic Elements