First the user should go through lcheck login test and once it is success then rest of the ajax requests and home request too.

I am new to jMeter and i have to do load testing for my website. I want to achieve this for 500 users on concurrent sessions. On my website once the user logs in there 7 ajax calls to render data on the home page. So I want to capture time for total 8 requests i.e after logging in, the home page request and then the rest in sequential manner. I tried to record my login event using blazemeter and then tried exporting .jmx file and using it in jMeter but its not helping. 3 of the requests are failing ,maybe they are not going in a sequential manner because for these requests to happen the user should be logged in.

Is there any way to achieve this Kind of scenario ?

Properly load testing AJAX requests is a tricky thing as they are executed in parallel, i.e. when real user using real browser logs in - 7 parallel requests are being fired at the same time.

This can be worked around if you use Parallel Controller to represent these AJAX requests. You can also put the main request and the Parallel Controller under a Transaction Controller to get cumulative time for all requests.

Also don't forget about correlation, in the absolute majority of cases you cannot just record and replay your test as modern web applications widely use cookies, session identifiers, tokens, etc. for security and client-side state tracking reasons. It means that at least one request parameter will change each time you execute the request therefore you need to extract it from the previous response.

So your test plan outline would be something like:

  • HTTP Cookie Manager (to represent browser cookies)
  • First HTTP Request (open login page)
  • Transaction Controller
    • Second HTTP Request (perform login. Here you will need to replace recorded hard-coded values with JMeter Variables from the previous step)
    • Parallel Controller
      • AJAX Request 1
      • AJAX Request 2
      • ...
      • AJAX Request 7
  • My site uses Csrf token. In the http cookie manager should i provide anything or leave it blank. Because i dont know what is the csrf token getting generated. – Nishant Kumar Aug 8 at 7:49
  • CSRF token should come with the very first request either in body or in headers or in cookies. You need to extract it and pass along with the second request. See How to Load Test CSRF-Protected Web Sites for example of bypassing CSRF protection in JMeter test – Dmitri T Aug 8 at 8:13
  • I have added a screenshot of my test plan i am doing now with my question asked. Can you just clarify on this as what is wrong i am doing ? I want to do check login for ever user then home and the other ajax requests. – Nishant Kumar Aug 8 at 8:49

Load testing of the AJAX request is not easy and at the same time if we just record and play the same scenario won't work sometimes.

You have to use correlation in order to extract a particular parameter from the earlier request, for example like the - sessionid or the tokenid and then it needs to be passed to the next request so that they will work.

For the above example try using a Simple controller and then place the main request and the parallel controller under it. And then place all the AJAX request under the parallel controller (bzm - Parallel Controller).

So your test plan outline would be something like:

  • HTTP Cookie Manager (to represent browser cookies)
  • HTTP Cache Manager
  • First HTTP Request (open login page)
  • Post-Processor (to extract parameters and store them into JMeter Variables)
  • Simple Controller
  • Think Time
  • Parallel Controller
  • AJAX Request 1
  • Header Manager for request 1 ( Pass on the extracted parameters in this request)
  • AJAX Request 2
  • Header Manager for request 2 ( Pass on the extracted parameters in this request)
  • ....
  • AJAX Request n Header
  • Manager for request n ( Pass on the extracted parameters in this request)
  • which Post-Processor i should select as my login page response has one csrf token. – Nishant Kumar Aug 8 at 9:29
  • I dont have Parallel Controller as option in my logic controllers dropdown. From where to get this parallel controller ? – Nishant Kumar Aug 8 at 14:21

You can use the Regular Expression Extractor/ XPath Extractor that will help you get the Csrf token from the earlier request and then pass it on to the other request in header manager.

For more info on how to use it you can refer to the following videos:

https://www.youtube.com/watch?v=7-NcyZuUQnw - Regular Expression Extractor https://www.youtube.com/watch?v=U9ycWhE1XXE - XPath Extractor

You can do that through the Plugins manager. Google it out on how to install plugins manager, its a simple process.

Refer the following video if necessary:

https://www.youtube.com/watch?v=ftxtr0pvxXA

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.