3

Has anyone tested sorting with Selenium? I'd like to verify that sorting a table in different ways work (a-z, z-a, state, date, etc.). Any help would be very much appreciated.

/Göran

5 Answers 5

2

Before checking it with selenium, You have to do small thing. Store the table values(which comes after sorting) in a string or array.

Now perform the sorting using selenium and capture the new list as

string new_list= selenium.gettable("xpath");

Now compare both the values and check whether they are same or not.

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

Comments

1

I have shared a strategy to test sorting feature of an application on my blog. You can use this to automate test cases that verify the sorting feature of an application. You could use it on place like the search result page, item listing and report module of the application. The strategy explained does not require creation of test data and is fully scalable.

Comments

0

You can get value of fields like this:

 //div[@id='sortResult']/div[1]/div  (this'd be row 1 of the search result)
 //div[@id='sortResult']/div[2]/div   ( row 2)

(I'm making some assumptions about the HTML structure here, but you get my drift...)

These can be quite fragile assertions, I'd recommend you anchor these xpath references to an outer container element (not the root of your document, as lots of "automatic" tools do).

When you click sort, the value changes. You'll have to find out what the values are supposed to be.

Also watch out for browser compatibility with such xpaths. They're not always ;)

Comments

0

The way I approached this was to define the expected sorted results as an array and then iterate over the results returned from the sorted page to make sure they met my expectations.

It's a little slow, but it does work. (We actually managed to find a few low-level sorting defects on multiple pages this way..)

Comments

0

You could use the WebDriver API from Selenium 2.0 (currently in alpha) to return an array of elements with the findElements command before and after the sort. This becomes a bit more difficult however if what you're sorting is paginated.

Comments

Your Answer

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