Testing AJAX-centric applications
In today's stack of web applications, it is almost unthinkable to build an application without some dynamic content being retrieved from a backend service. Most of the time, these applications tend to lean towards partial page fresh. That is, only the needed sections of a rendered page are refreshed as opposed to the whole page loading its entire content again. This leads to more responsive pages, which improves the overall experience of the user.
How to do it…
In this recipe, we will walk through how you can test such applications using JMeter. Perform the following steps:
- Launch JMeter.
- Add HTTP(S) Test Script Recorder and set it up for recording (see the Recording a script via JMeter HTTP proxy recipe).
- Click the Add suggested Excludes button.
- Start the HTTP(S) Test Script Recorder.
- Point your browser to https://maps.google.com.
- Perform a couple of searches in the provided search box (for example, pizza, restaurants, hotels, and so on).
- Click on a few of the returned results.
- Repeat steps 6 and 7 two more times.
- Stop the HTTP(S) Test Script Recorder.
- Add a listener to your test plan.
- Save and run the test plan.
How it works…
The actions of the user are tracked and recorded via the script recorder we set up in step 2. Like traditional web applications, we record all actions and exclude irrelevant static resources, such as images, JavaScript, and style sheets. Calls that trigger backend server calls are trapped and are available for replay later. At the end, we have a script that is almost identical to what we would get when recording a traditional web application.
There's more...
AJAX-centric applications tend to involve a lot of asynchronous server requests made from within the client (frontend). These calls are normally made from embedded script tags within a view technology, for example, HTML, Java Server Pages (JSP), Groovy Server Pages (GSP), or from an included JavaScript file in the page. As such, JMeter records all such server requests and they can be played back at the time of running our test plans. This allows us to simulate the intended load on our servers, as though the application was the one making the AJAX calls.