Search code examples
c#automated-testskendo-gridui-automationatata

Getting an IEnumerable of all values in a certain column


I'm currently working with the Atata framework and using a Kendo grid. What I'm trying to achieve is getting an IEnumerable or a collection containing all the values in a column. The kendo grid is defined as below:

public KendoGrid<TransactionGroupsRow, _> TransactionGroupsGrid { get; private set; }

public class TransactionGroupsRow : KendoGridRow<_>
    {
        [FindByColumnHeader("Group Name")]
        public Link<_> GroupName { get; private set; }
    }

I not only want a collection of all the links GroupName, I specifically want the text component of them i.e. what the link would read like on the screen.

An example of the links and their text

So in this example I would want an IEnumerable containing "002999" and "003999".

Let me know if I need to provide additional detail. Thanks in advance!


Solution

  • There are 2 ways to do that.

    1. Use SelectData method. It works quite fast for list of items with count <= 50.

      // Just get all items:
      IEnumerable<string> groupNames = page.TransactionGroupsGrid.Rows
          .SelectData(x => x.GroupName.Content.Value).Value;
      
      // Assert items:
      page.TransactionGroupsGrid.Rows
          .SelectData(x => x.GroupName.Content.Value).Should.Contain("002999", "003999");
      
    2. The faster way is using SelectContentsByExtraXPath method. This one will work very fast even for a table with 1000 rows. But you need to specify a relative XPath to the table cell td element inside a row tr element. This can also be extracted to the page object class as a method.

      // Just get all items:
      IEnumerable<string> groupNames = page.TransactionGroupsGrid.Rows
          .SelectContentsByExtraXPath("td[1]", "Group Names").Value;
      
      // Assert items:
      page.TransactionGroupsGrid.Rows
          .SelectContentsByExtraXPath("td[1]", "Group Names").Should.Contain("002999", "003999");
      

    You can also check Performance Practices for ControlList Atata sample project.