How to execute Ajax requests in JMeter?

16.1k views Asked by At

I want to execute Ajax requests in JMeter. I record my test plan with JMeter and BlazeMeter but none can handle Ajax requests. How can I solve my problem?

Or is there any tool that can send concurrent Ajax requests?

Thanks in advance, M.A

4

There are 4 answers

9
Naveen Kumar R B On BEST ANSWER

By default, Ajax requests can't be simulated by JMeter as it does not process .js files (As of 3.1 version). You have to explicitly add the requests (HTTP Samplers) for AJAX requests.

Use Network tab of a browser (F12 option) and filter the traffic by xhr, which shows only AJAX requests. Add those requests as HTTP Samplers in the script at the point you needed in the Test Plan.


Browser can process .js files, hence AJAX requests are sent from the browser. When you record the script using HTTP Test Script Recorder, as you are using the browser to navigate, even AJAX requests (originated from js files) will also be added/recorded to the Test Plan.

Since JMeter can't process .js files due to limitation, manually add the AJAX requests (nothing but HTTP Get or Post requests) using HTTP Sampler, if you are building the Test Plan without HTTP Test Script Recorder.

Note: If you are using HTTP Test Script Recorder, no need to add them manually as they are already recorded in the Test Plan.

5
Hassen Bennour On

you can do that by recording http traffic with JMeter Proxy

http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

but it is only possible to replay the same traffic, can be problematic for sessions, cookies... Better solution is to use WebDriver

https://jmeter-plugins.org/wiki/WebDriverTutorial/

https://jmeter-plugins.org/wiki/PluginInstall/

the needed package is https://jmeter-plugins.org/files/packages/jpgc-webdriver-1.4.0.zip

0
Dmitri T On

It is not possible as kicking off more threads than originally defined in the Thread Group is not currently supported, the feature is being tracked as Bug 53159. AJAX requests are "normal" HTTP Requests so JMeter can record and replay them, but when it comes to asynchronous execution - you cannot do this as of now. The workaround options are in:

  1. Use WebDriver Sampler plugin so each JMeter virtual user will kick off a real browser. Warning: this way is very resource intensive.
  2. Use scripting, i.e. JSR223 PostProcessor to kick off AJAX-driven requests via Apache HttpComponents
  3. Develop your custom sampler. You can use the current way of handling embedded resources as a reference.

Learn more: How to Load Test AJAX/XHR Enabled Sites With JMeter

0
montag451 On

I had this same problem after recording samplers using the JMeter Proxy. The answer was on this blog post: https://lincolnloop.com/blog/load-testing-jmeter-part-1-getting-started/ - see the Ajax Requests section.

Add an HTTP Header Manager for the ajax request and make sure you are sending the X-Requested-With:XMLHttpRequest header.