0

I have some data tables with filters and sorting. Whenever I filter the data table with certain criteria the rows on the table change.

Let's say I have a user list in the data table and I filter users based on whether they are admin users or normal user, so if I select admin users with the filter drop-down, only admin users are shown.

Many of these kinds of filtering data changes do not reflect data table in any way other then data itself changes. Testing based on the data itself is not reliable because it is changing too fast.

What would be the best way to test that filtering/sorting is working properly?

One idea I had was to add data attributes to the table columns with the desired data and checking with web driver whether they satisfy the criteria.

<table>
  <tr>
    <th>User Id</th>
    <th>Username</th>
    <th>Email</th>
  </tr>
  <tr>
    <td data-qa-user-type="admin">1</td> <!-- Note the data attribute -->
    <td>Maria</td>
    <td>[email protected]</td>
  </tr>
</table>
4
  • So what is the exact question here? Commented Feb 24, 2018 at 7:43
  • What would be the best way to test these kinds of data manipulation changes. Commented Feb 24, 2018 at 7:47
  • Isn't there a script which says <!-- Note the data attribute -->. I think the data attribute will be key to your validation. Commented Feb 24, 2018 at 7:49
  • Yes, that was one of my ideas. Commented Feb 24, 2018 at 7:53

1 Answer 1

1

If you are looking to check whether your filters are working correctly you can go with WebElements as like in this code snippet :

element = driver.find_elements_by_xpath("//td[@data-qa-user-type='normal']")
if len(element) == 0 :
    print("pass")
else :
    print("fail")

In this if particular type of user is found(normal user) your assertion fails.

If the page is not refreshed we can either refresh the page or wait based on appearance or disappearance of some particular element after analysing the changes in the dom. Now for checking whether data is in sorted order we can do something like :

# now checking for sorted elements or not
element = driver.find_elements_by_xpath("//td[@data-qa-user-type='admin']//following-sibling::td")
originalList = []
for i in range(0,len(element),2) :
    originalList.append(element[i].text)
sortedList = sorted(originalList)
if originalList == sortedList :
    print("pass again")
else :
    print("Fail")

Hope it helped.

Sign up to request clarification or add additional context in comments.

5 Comments

That is a very good idea. Thanks. It would also be interesting what would be the options to test sorting on the data table
@Shota : Are you querying something ? I am bit confused.
It is the single page application written on React, so the page is not refreshed after sorting the data table if this is what you are interested in.
@Shota: Updated the answer can you confirm is it what you are looking for.
this code is written with phyton how can I modify it with java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.