Book Image

JMeter Cookbook

By : Bayo Erinle
Book Image

JMeter Cookbook

By: Bayo Erinle

Overview of this book

Table of Contents (16 chapters)
JMeter Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Launch JMeter.

  2. Add HTTP(S) Test Script Recorder and set it up for recording (see the Recording a script via JMeter HTTP proxy recipe).

  3. Click the Add suggested Excludes button.

  4. Start the HTTP(S) Test Script Recorder.

  5. Point your browser to https://maps.google.com.

  6. Perform a couple of searches in the provided search box (for example, pizza, restaurants, hotels, and so on).

  7. Click on a few of the returned results.

  8. Repeat steps 6 and 7 two more times.

  9. Stop the HTTP(S) Test Script Recorder.

  10. Add a listener to your test plan.

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