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.
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:
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.
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:
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.