Testing AJAX Web Applications, Part I

In previous blog entries I’ve described how AJAX (Asynchronous JavaScript And XML) technology can be used by Web developers to greatly improve the speed and performance of Web applications. But because AJAX operates asynchronously, normal testing techniques just don’t work. A standard approach for testing a non-AJAX Web application is to programmatically send a synchronous HTTP request, which corresponds to the request which would be sent by a user action such as a button-click, to the Web server and then programmatically fetch the HTTP response and then examine the response to determine if the test case passes or fails. None of this scheme works for AJAX-enabled Web applications. First of all, AJAX applications use a special XML-HTTP asynchronous request mechanism. And second, because the request-response operations are asynchronous and work behind the scenes, there is no easy way to determine when the response is complete. Now this is not to say that you can’t test AJAX applications, I’m just saying that you have to use different techniques. One successful testing scheme I’ve used is simple in principle but tricky in the details. The idea is to use the Internet Explorer DOM (Document Object Model) and JavaScript to fire an event which corresponds to the user action that generates the Web application’s AJAX operation. Then wait until the asynchronous response has completed, and use the IE DOM and JavaScript to examine the resulting state of the Web application to determine a pass or fail result. The picture at the bottom of this entry shows you what I mean. I’ll continue with this interesting idea next time.

This entry was posted in Software Test Automation. Bookmark the permalink.