Using JMeter and Firefox to load test

I spent some time recently building an application using AJAX technology – which simply means a collection of client side JavaScript and XML that asynchronously retrieves data from the server in the background only when needed so as to minimize the impact on the user experience. Once the basic application was up and running, I wanted to run some performance test and thanks to the abundant availability of cloud based compute resources, it was easy to quickly and inexpensively put together a performance testing environment. The trouble is that it isn’t so easy to automate a load test on a dynamic AJAX based application, especially if there are no static DOM identifiers to include in the scripts. So, I came up with a quick hack to push AJAX actions through Firefox’s proxy configuration to record a JMeter script.

Here are some simple steps for recording an AJAX session using Apache’s JMeter.

1. Create a new JMeter Test Plan

2. Add a HTTP Request Defaults config element
# This can be used to specify defaults for you entire test suite
+ Specify your Server Name or IP address and any required port #

3. Add a HTTP Cookie Manager config element
# This can be used to control and manage the cookie policy across the test

4. Add a Thread Group
# No need for multi-threaded recording, so:
+ Specify 1 thread, 1 sec ramp up time and loop count of 1

5. Add a Once Only Controller
# My application has a user login that also generates a session, cookie
# If your application does not, you can skip this step and the next

6. Add a HTTP Request Sampler to the Once Only Controller
# Here you specify the protocol method (put/get), path to the request and any parameters

Now, lets set up Firefox to proxy actions. Bring up the Firefox browser and under Tools/options/advanced tab/network tab/settings button/”Manual proxy configuration”
+ Set 127.0.0.1 port 9090
+ Enable the “Use this proxy for all protocols” check box

And when ready to start recording the browser action just bring up the HTPP Proxy Server within JMeter and click Start. Everything that is done within Firefox will be recorded in JMeter’s recording controller. When done, just click the Stop button on the HTTP Proxy Server within JMeter.

That’s it, the JMeter script that was created above now has all the AJAX data recorded and it ready to replay. JMeter has built in capacity to run the script and generate a load. I recorded a few different JMeter scripts and using a couple of cloud instance and the JMeter command line interface, I simulated the AJAX action of many thousand of clients with offset timing.

I am not exactly sure what you mean by not working – nothing shows, wrong codes, etc…?One potential problem is that AJAX response codes are UTF-16 and JMeter uses a java html page to display results which may not be capable of handling UTF-16. You could try saving results to a file and see if you get better results.

What If the browser answers with just JavaScript code?
And this code is what bults up the entire page… i.e. you send a post to the server… and it answers 200 OK with javascript code as answer… we miss all the gets… that come along….

Although JMeter is capable of recording AJAX calls it won’t replay them properly. AJAX calls are executed in parallel, each call by separate thread, and JMeter doesn’t provide any relevant sampler implementing this behavior and allowing to override parent thread group limitations. However it’s possible with some scripting. See How to Load Test AJAX/XHR Enabled Sites With JMeter for example samplers details