Ajax Testing with Jmeter

Initially when I tried to do Load testing with Ajax I found that it was not an easy job to do, especially when DWR concept is involved, I didn't find any good solution on web, so decided to dig in and give it a try on my desk top and found that handling Ajax with DWR in Jmeter is pretty simple but not that easy.

Here I am assuming that Ajax is implemented using DWR.

Before start recording you need to consider which version of DWR is used, based on the version of DWR we need to choose the recording approach. This approach will vary with DWR 1.3 and above 1.3

So considering the steps involved for DWR version 1.3

1. Record the scripts as you do normally.
2. Have the listener "View result tree" which will help in debugging the scripts.


Fig 1

From the above figure we can see that few of the DWR calls have been captured. One thing to be noticed is that right hand panel shows “Name/Value” pair and the method used is "POST". The value captured is in single line and initially default to understand what it is. NOTE: - Don’t edit the value from Jmeter UI, It will screw up the scripts. We need to edit it in JMX file, Use Text Pad or any other editor to edit the JMX file.

After editing notice that each DWR calls will have unique id, this ID will differ for each run.

c0-id=323_1456789521

Handling this id in such a way that new value will be generated for each run. In order to do this generate random numbers, We can see that id is split in to 2 parts separated by "_" so for first 3 digit generate 1 random number and for last 10 digit generate another random number. After modification it will look some thing like this.

c0-id=${dwr1}_${dwr2} Make sure you edit in JMX file.

In Order to generate the Ramdom numbers use "Random Function". This function looks like this
${__Random(100,400,test)} for dwr1 variable
${__Random(100000000000,200000000000,test1)} for dwr2 variable.

In order to access these value use an "User Defined Variable" you can see in the below figure


Fig 2

dwr1 and dwr2 is the variable name which should be used to generate the id value. Now save the Jmx file and restart the Jmeter. when u run the script 1st DWR call will run with out any problem (figure 1 you can see that there are 3 DWR calls recorded) but fallowing DWR calls may fail some times, If you face the problem for running the next DWR calls, You need to change the content type of the request to "text/plain". In order to do these add the "HTTP Header Manager" config element and set the content type to text/plain

Name field=Content-Type
value=text/plain


Fig 3
If you fallow above instruction you can easily handle the Ajax calls with DWR version 1.3

For DWR version greater than 1.3 needs to be handled in little bit different way

1. Record the scripts for the pages where Ajax is implemented.

2. Once recording is completed you should be able to see the request some thing like
xyz/dwr/engine.js, if you don't find this request then close the browser and open it newly and start recording again. This request will only be recorded when new browser is opened.

3. This version of DWR uses two session variable

JSESSIONID and SCRIPTSESSIONID
You need to capture these values and substitute it in JMX file where ever it is being used. In order to do this, add 2 RegularExpressionExtractor under dwr.engine.js request

For Jsessionid

Reference Name: jsessionid
Regular expression: dwr.engine._origJSessionId = "(.*)";

You can get this jsessionid from cookie manager also.

For ScriptSessionid

Reference Name: scriptsessionid
Regular expression: dwr.engine._origScriptSessionId = "(.*)";

Above things is w.r.t DWR 2.0 version.

4. Now use these variable to substitute the value and run the script.

Tip:-If you are not able to record any of the DWR calls then use HTTP Analyzer or any tool and create your own HTTP request and method should be POST.

Comments

  1. Hi,
    very good post, it helped me a lot thx

    ReplyDelete
  2. Hi, I have a doubt, I am new to JMeter and AJAX applications. As per your post, i am assuming our application uses DWR1.3. The issue here is, i found a .js request and i ddisabled it and went ahead with running the scripts. The scripts run fine for say 2 or 3 or max 4 users but fail for any number more than that. Other than that scripts always run fine for single users. I am really confused and under lot of pressure to debug the issue at the earliest. Can you pls suggest any work around? Thanks in advance.

    Regards
    Soujanya

    ReplyDelete
  3. Please do let me know the steps to proceed the jmeter ant task I am not able to figure out the changes.

    ReplyDelete
  4. Nice article, its very informative content..thanks for sharing...Waiting for the next update.

    Swift Online Course
    learn swift online
    swift online training

    ReplyDelete

Post a Comment

Popular posts from this blog

Running Junit Cases with Jmeter(Basic)

JDBC Testing with Jmeter