New to Telerik Test Studio? Download free 30-day trial

Data Driven Find Expressions in Coded Step

I need to data drive an element's find expression and use it to perform an action against or verify an element.

Tip! Data driven find expressions is also available directly in elements Edit mode.

The Scenario

The example below uses a page from the Telerik UI for ASP.NET MVC demo site.

  1. Create a test and navigate to the demo page.
  2. The ListBox on the left side holds a list of names under the Employees list.
  3. Select a name and choose the button to move it on the right.
  4. The selected name is now moved to the right under the Developers list.
  5. Do consecutive iterations for each of the names in the list on the left.

The Solution

  1. Create a test and record the Navigate step.

  2. Prepare the data table - for this example I use the internal data source and it looks like this.

    Data source

  3. Explore the list of items and its structure using the Advanced Recording Tools.

    Highlight Items from list to explore

  4. Based on the DOM tree the items from the list are identified as ListItems with specific InnerText property and class=k-list-item. These element's attributes are used when defining the find expression for the element in code.

  5. Create a coded step in the test.

  6. Start with getting the value from the data source and store into a variable.

  7. Next use the value of that variable to define the string, which needs to be used in the find expression definition.

  8. Form the find expression definition and assert a matching element exists on the page.

  9. Click the matching element.

    Complete coded step looks like this:

        // Get current iteration value from data source
    var dataIterVal = Data["EmplNames"];
    
    // Define a string which adds the value taken from data source as inner text for the find expression
    string defForFE = "InnerText="+dataIterVal.ToString();
    
    // Search for the list item element using find expression with the help of the defined string value           
    HtmlListItem nameToSelect = Find.ByExpression<HtmlListItem>("class=k-list-item", defForFE );
    Assert.IsNotNull(nameToSelect);
    
    // Click the corresponding item from list
    nameToSelect.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 0, 0, ArtOfTest.Common.OffsetReference.AbsoluteCenter);
    ```
    

    10.  Switch back to the test steps and record the click on the button to move the selected item on the right. With this the scenario is complete.

    Recorded step to move the item on the right

In this article