Using Badboy with AJAX Web Sites

Many modern web sites and applications use a technique known as "AJAX" for updating content on a page in the background without refreshing the page. Badboy is designed to support recording and playing back this type of application. This section explains how Badboy handles AJAX web pages and gives some tips for creating successful tests.

It's possible to record and play back AJAX web pages using Badboy in either Request Mode or Navigation Mode, however for functional testing in general you'll get better results if you use Navigation Mode. Read on below for discussion of why this is and how Badboy handles AJAX pages in these two modes.

Understanding AJAX Requests

AJAX requests differ in important ways from regular requests. The most important aspect of AJAX requests is that they do not directly cause the web browser to load a new page when they complete. Instead, when AJAX requests complete they invoke an existing JavaScript function on the page that launched the AJAX request. This JavaScript function can do all kinds of things - it can update the page dynamically, set JavaScript variables, fill out forms on the page - it may even launch more AJAX requests or cause a real page load to occur.

Recording AJAX Pages in Request Mode

When you record in Request Mode Badboy detects and records AJAX requests directly in your script. AJAX requests look similar to regular requests but they are colored gray. The table below shows how AJAX requests look compared to normal requests:

Normal Request
AJAX Request

Playback of AJAX Requests

Because of the different nature of AJAX requests, Badboy plays them differently to normal requests. Badboy sends the AJAX request to the server but it does not invoke the subsequent JavaScript call that handled to the original request. This important difference means that when Badboy plays an AJAX request you may not see the screen update as it does when same action happens manually. However what has happened is that the web server has processed the request and now believes and behaves as if the page is updated. Since updates may be missing from the screen after an AJAX request exedcutes, you might not be able to use Assertions that check the content of the page to verify that the AJAX request succeeded.

Since there can be occasions when the user interface becomes out of date with the server when playing back AJAX Requests, it can be useful to deliberately record actions that cause a page load after you have executed the AJAX request. Then you can do the usual content check Assertions to check the results of the request.

You might worry that your test will then not function correctly because the subsequent activity caused by an AJAX request is not executed. However this is generally not problematic because Badboy records all the interactions with the web server: if the AJAX request went on to make another AJAX request then Badboy will have recorded the subsequent request and will play it back. On the other hand, if the AJAX request actually invoked a page load then Badboy will have recorded that as well. So although there may be cases where the user interface does not reflect the updates caused by an AJAX request, the server is always kept correctly updated, and the next page load will cause correct content to be displayed.

The possibility that the screen may not be updated after an AJAX call is the primary reason that it's generally better to record AJAX pages in Navigation Mode. Request Mode is mainly useful for two purposes: executing Load Tests with the Raw Browser Engine, or exporting your script to JMeter. Outside of these purposes you should usually be using Navigation Mode for testing AJAX based web sites and applications.

Recording AJAX Pages in Navigation Mode

For functional testing, Navigation mode is generally the best mode to use in recording AJAX based web applications, at least for those specifc actions in the application that use AJAX requests. In fact, you probably won't notice any difference to how Navigations are recorded for AJAX interactions. However if you inspect closely you will see some small differences:

  • If you open the properties you will see the "Passive Navigation" option is selected
  • Underneath the Navigation item you may see an AJAX Request item () recorded to show the AJAX request that occurred when the item was clicked

Playback of AJAX Pages in Navigation Mode

When AJAX interactions recorded in Navigation Mode are played back Badboy does not do anything specific to initiate the AJAX request. Rather, it simulates a mouse click on the element so that the web browser initiates the AJAX interaction just as if the user had done it.

Once the AJAX request has been initiated by the browser, Badboy observes it, waits for it to finish, and then records the response time, size and other attributes are recorded as a Response for the Navigation.

After the AJAX request completes the browser invokes all the normal handling that occurs when the page is navigated manually. Because of this the page updates with new content and you can use Assertions to check the displayed content on the page just as you would in a non-AJAX application.


Badboy Documentation Generated on Mon Dec 29 22:28:40 EST 2008