In the last tutorial, we discussed how you can leverage Find Element functionality to recognise elements based on different attributes. In this, we will find out How to Find Elements with Data Binding in Telerik.
Let’s pick following test case for execution.
- Open bing.com
- Provide a search string
- Click on search button
- Validate that the first result contains the search
The first step will be to record the test case and bind it with the Test data sheet.
Lets have a look at the element properties for last verification step.
To start, right click on the Test step whose element you want to edit and then choose Run => To Here from the context menu that appears. A browser will be opened and the test will run till the selected step. Now, right click on the corresponding element in the element explorer and select “Edit in Live” from the menu.
Find element dialog will open.
Have a look at the “TextContent” attribute of the element. So, the verification element has been defined as a text that is exactly “Toolsqa”, this means that Test Studio will always look for “Toolsqa” text in the webpage, whenever this step is executed.
Lets say there is an another scenario where the user wants to enter any other search string such as “Apple”, then this test script will fail on the verification step as Test Studio will not be able find any “Toolsqa” in the search result page.
To overcome these scenarios, Test Studio allows users to data bind variables as element attributes.
So, once you have attached data source to your test and open “Find Element” dialogue box, you will find that the element property textbox has been transformed into a drop down. Click on the dropdown and it will show the column names from the Test Data source.
From the drop down, select the column which contains your search string and click on the set button. We have kept our search string in column2 so we will select Column2.
Column2 will be added as the element property. Here, we are matching TextContent with Column2 as “is Exactly” this will tell Test Studio to find the exact same text in the search result page as provied by the user.
So, if the Result appears as toolsqa.com then Test Studio might not recognize it will look for an exact relation. So, we will change this to something broader or more generic like starts with or contains. You can choose anything that is applicable as per your scenario.
Now let’s quickly execute the Test Case and validate that the Test Studio is able to identify the verification element based on the data entered through the Test Data Sheet.