Thursday, January 22, 2009

Watir Sortable Tip

Haven't posted much recently, maybe that will change. Maybe not...

I recently needed to do some Watir testing against a UI that made use of the Sortable features of script.aculo.us.

I wasn't really interested in writing all the code to simulate drag and drop I just wanted to change the order and verify some behavior that made use of the order. I dug around in the script.aculo.us docs and found this: Sortable.setSequence(element, new_sequence).

Using this I can inject a bit of javascript into the page I'm testing that will force the sort order to a particular order. For example, if I have a basic Sortable on the page, I can force the order to be whatever I need by doing the following from my Watir script:

@ie.Document.parentWindow.execScript("Sortable.setSequence('sortorder', [5,1,3,2,4]);")


In this case the Sortable is using _X as the sort ID, but any values will work as long as they match the pattern used in the web page.