Selenium, AJAX, DHMTL
It’s a well known fact that Selenium can occasionally be tricky with very rich JS based sites. After recently having the fun of putting together a bunch of Selenium tests to back up some UAT scripts, I came across a few things that have been helpful in getting things to work
- waitForVisible - In the application I was working on, a lot of AJAX requests would trigger a display change in the application, with an elements visibility being toggled. There are other methods for handling AJAX request/response cycles (pause, custom extensions to catch the ajax response), and I’ve found myself using pause in some instances, waitForVisible has slowly become my favourite. Custom extensions can be done simply with things like jQuery’s ajaxStop, but it’s not as portable to JUnit based tests, which I need.
- clickAt - I’ve found that having dynamic behaviour that isn’t triggered by an anchor tag doesn’t quite work if using click. clickAt seems to work great though.
- select|element|option label - The selenium IDE outputs two separate events for opening a select then explicitly clicking the option within, but found that this is unreliable. Simply putting the option label into the initial select command works fine.
- waitForTextPresent - I try and avoid using this as a direct handler for waiting for an AJAX request. The firefox test runner seems to suffer a serious performance problem when using this (at least, in my app it does), and a request that might take a couple of tenths of a second can end up taking several seconds.