Testing ajax-heavy applications

34 views
Skip to first unread message

alex finn

unread,
Jan 14, 2011, 9:54:43 AM1/14/11
to pyccuracy
Hi guys,

I've been playing with pyccuracy more and started to work on test
scenarios on the application that I actually want to test. One problem
that I had is that my app is very ajax-intensive and there is no OOB
method to wait for ajax request to complete.
I started from validating the visibility of my "Loading..." indicator
and it works most of the time but sometimes it fails and it seems to
be very much of a timing issue so this method is not 100% reliable
which is not very encouraging to me :)
After playing around for a while, I was able to come up with the
following solution. Since I'm using jQuery and all ajax requests are
done via this library, I can globally verify if there are any active
ajax requests by checking jQuery.active variable.
So here is the code I used in my action:

class PageLoadCompleteAction(ActionBase):
regex = r'^(And )?I wait for ajax page to load$'

def execute(self, context, *args, **kwargs):

context.browser_driver.selenium.wait_for_condition('selenium.browserbot.getUserWindow().jQuery.active
== 0', 10000);

I found similar solutions for Prototype and Dojo (attributes are
Ajax.activeRequestCount and dojo.io.XMLHTTPTransport.inFlight.length
respectively) and I'm sure there can be a solution for the other
libraries as well or you can implement such flag on your own.
If this is something potentially useful for others you may consider
putting this code to the SeleniumDriver (ie wait_for_ajax_requests
method) so that it is easier to use it in actions.

Diogo Baeder

unread,
Jan 17, 2011, 7:24:20 PM1/17/11
to pycc...@googlegroups.com
Hi there, Alex!

First, sorry for the delay.

It would be a really interesting idea to have a better integration of
Pyccuracy and the browser JavaScript environment; but to get there we
have to pass through the browser, respecting its way to access
JavaScript, as explicited by your example. This is a tricky point, since
each browser implements its own JavaScript access means, and not all
browsers have JavaScript support - like the ones that don't rely on a
GUI browser and just parse the document from the HTTP response -.

Coding a method to identify Ajax states by the way you mentioned ads
even more coupling, because now SeleniumDriver will have to know which
JS library the UI code is using - jQuery, in your case -. Maybe that
could be a job to something like a jQuerySeleniumDriver, though, or we
could make something like a new JavaScriptedDriver interface that ads
some more methods concerning to JavaScript.

Anyway, my point is: implementing Ajax-related code in the
SeleniumDriver would be too much responsibility for it to manage, but
there can be better choices to implement it - can you point us other
ways to accomplish this? What about forking the repo and sending a pull
request? ;-)

Thanks for the help with Pyccuracy, Alex! Let's make it better together! :-)

Diogo

--
Diogo Baeder - desenvolvedor web
http://diogobaeder.com.br

alex finn

unread,
Jan 20, 2011, 3:53:52 AM1/20/11
to pyccuracy
Hi Diogo,

first of all, I totally agree that SeleniumDriver should not be that
much coupled with javascript and any library in particular. However,
considering that most of the modern web apps are using ajax a lot and
would probably like to test this functionality, I'd say that an
extended browser driver would be a very nice feature for pyccuracy.
I do not think it should be limitted to jQuery since the same approach
works for most of the other frameworks (I found solutions for
prototype, dojo, google closure). However, I would suggest something
customizable so that end user can specify an attribute to monitor with
shortcuts for popular frameworks.
I will probably do a pull request once I have time to implement this
approach as for now I only did it for jQuery to test a particular
application.

Alex.

Diogo Baeder

unread,
Jan 20, 2011, 8:06:10 PM1/20/11
to pycc...@googlegroups.com
Hi, Alex,

Right now I can't think of a clean and decoupled way to implement that,
so I'm curious to see what you come up with. :-)

Thanks for the collaboration!

Diogo

--

Reply all
Reply to author
Forward
0 new messages