views:

402

answers:

3

Hi!

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

A: 

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 ;)

krosenvold
A: 

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..)

Peter Bernier
A: 

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.

Dave Hunt