Mike Johnston
Mike Johnston

Reputation: 233

Test/Automate table contents where case-insensitive sort is the only requirement, but that column has same-word different-case items

I need a way to test and verify that my UI table contents are populated with the correct items from the database and sorted correctly. Currently, I have a query that returns the data that I need (sorted case insensitively on one of the columns) from the DB and then places that query result into type DataTable. I then have a method in C#/Selenium that converts the UI's table contents into type DataTable. I want to do an Assert AreEqual or a custom assert on these 2 datatables to make sure they match.

But I am running into problems because the table that needs to be verified is sorted on a column that contains a bunch of same-word different-case items, and the requirements for said table specifies that this column should be sorted case insensitively.

So everytime I load the page, those same-word different-case items are sometimes at different indexes in the list/table. For example, I can load the page the first time and see:

NETWORK  COLUMNTHATISSORTED
Net1     word 1    
Net2     WORD 2
Net3     word 2
Net4     WORD 2
Net5     word 3

I can load the page a second time and see this:

NETWORK  COLUMNTHATISSORTED
Net1     word 1    
Net3     word 2
Net4     WORD 2
Net2     WORD 2
Net5     word 3

Based on the requirements, this is perfectly fine and not considered a defect. But for automation testing purposes, I cant think of a way to code for this. If I use a simple AreEqual Assert, the inconsistency of the same-word different-case items fails the test sometimes. How do I get around this with C# or Selenium code?

Upvotes: 0

Views: 72

Answers (1)

Linh Nguyen
Linh Nguyen

Reputation: 1138

You can sort the UI datatable before assertion, like:

datatable.DefaultView.Sort = "NETWORK";
datatable = datatable.DefaultView.ToTable();

Upvotes: 0

Related Questions