1

The user should go through the login test and proceed to the rest of the tests if it is successful.

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 are 7 Ajax calls to render data on the home page. I want to capture the time for 8 total 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 exporting a .jmx file to use in JMeter but it's not helping. 3 of the requests are failing. I think they may not be going in a sequential manner, because these requests require the user to be logged in.

Is there any way to achieve this kind of scenario?

4 Answers 4

2

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)
2
  • which Post-Processor i should select as my login page response has one csrf token. Commented Aug 8, 2018 at 9:29
  • I dont have Parallel Controller as option in my logic controllers dropdown. From where to get this parallel controller ? Commented Aug 8, 2018 at 14:21
0

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
3
  • 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. Commented Aug 8, 2018 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
    Commented Aug 8, 2018 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. Commented Aug 8, 2018 at 8:49
0

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

0

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 agree to our terms of service and acknowledge you have read our privacy policy.

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