如何在JMeter中执行Ajax请求?

时间:2020-12-30 20:02:56

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?

我想在JMeter中执行Ajax请求。我用JMeter和BlazeMeter记录我的测试计划,但没有人能处理Ajax请求。我怎样才能解决我的问题?

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

或者是否有任何工具可以发送并发Ajax请求?

Thanks in advance, M.A

在此先感谢,M.A

4 个解决方案

#1


3  

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.

默认情况下,JMeter无法模拟Ajax请求,因为它不处理.js文件(截至3.1版本)。您必须为AJAX请求显式添加请求(HTTP Samplers)。

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.

使用浏览器的“网络”选项卡(F12选项)并按xhr过滤流量,该时间仅显示AJAX请求。在测试计划中需要的位置将这些请求作为HTTP采样器添加到脚本中。


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.

浏览器可以处理.js文件,因此从浏览器发送AJAX请求。当您使用HTTP测试脚本记录器记录脚本时,当您使用浏览器进行导航时,即使AJAX请求(源自js文件)也将添加/记录到测试计划中。

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.

由于JMeter由于限制无法处理.js文件,因此如果您正在构建没有HTTP Test Script Recorder的测试计划,请使用HTTP Sampler手动添加AJAX请求(除了HTTP Get或Post请求)。

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

注意:如果您使用的是HTTP测试脚本记录器,则无需手动添加它们,因为它们已记录在测试计划中。

#2


0  

you can do that by recording http traffic with JMeter Proxy

你可以通过使用JMeter Proxy记录http流量来做到这一点

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

但它只能重播相同的流量,会话,cookie会有问题...更好的解决方案是使用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

所需的软件包是https://jmeter-plugins.org/files/packages/jpgc-webdriver-1.4.0.zip

#3


0  

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:

目前不支持启动比线程组中最初定义的更多线程,该功能被跟踪为错误53159. AJAX请求是“正常”HTTP请求,因此JMeter可以记录和重放它们,但是当它到来时异步执行 - 你现在不能这样做。解决方法选项包括:

  1. Use WebDriver Sampler plugin so each JMeter virtual user will kick off a real browser. Warning: this way is very resource intensive.
  2. 使用WebDriver Sampler插件,以便每个JMeter虚拟用户启动真正的浏览器。警告:这种方式非常耗费资源。

  3. Use scripting, i.e. JSR223 PostProcessor to kick off AJAX-driven requests via Apache HttpComponents
  4. 使用脚本,即JSR223 PostProcessor,通过Apache HttpComponents启动AJAX驱动的请求

  5. Develop your custom sampler. You can use the current way of handling embedded resources as a reference.
  6. 开发您的自定义采样器。您可以使用当前处理嵌入资源的方式作为参考。

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

了解更多:如何使用JMeter加载测试启用AJAX / XHR的站点

#4


0  

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.

使用JMeter代理记录采样器后,我遇到了同样的问题。答案在这篇博客文章中:https://lincolnloop.com/blog/load-testing-jmeter-part-1-getting-started/ - 请参阅Ajax请求部分。

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

为ajax请求添加HTTP标头管理器,并确保发送X-Requested-With:XMLHttpRequest标头。

#1


3  

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.

默认情况下,JMeter无法模拟Ajax请求,因为它不处理.js文件(截至3.1版本)。您必须为AJAX请求显式添加请求(HTTP Samplers)。

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.

使用浏览器的“网络”选项卡(F12选项)并按xhr过滤流量,该时间仅显示AJAX请求。在测试计划中需要的位置将这些请求作为HTTP采样器添加到脚本中。


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.

浏览器可以处理.js文件,因此从浏览器发送AJAX请求。当您使用HTTP测试脚本记录器记录脚本时,当您使用浏览器进行导航时,即使AJAX请求(源自js文件)也将添加/记录到测试计划中。

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.

由于JMeter由于限制无法处理.js文件,因此如果您正在构建没有HTTP Test Script Recorder的测试计划,请使用HTTP Sampler手动添加AJAX请求(除了HTTP Get或Post请求)。

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

注意:如果您使用的是HTTP测试脚本记录器,则无需手动添加它们,因为它们已记录在测试计划中。

#2


0  

you can do that by recording http traffic with JMeter Proxy

你可以通过使用JMeter Proxy记录http流量来做到这一点

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

但它只能重播相同的流量,会话,cookie会有问题...更好的解决方案是使用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

所需的软件包是https://jmeter-plugins.org/files/packages/jpgc-webdriver-1.4.0.zip

#3


0  

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:

目前不支持启动比线程组中最初定义的更多线程,该功能被跟踪为错误53159. AJAX请求是“正常”HTTP请求,因此JMeter可以记录和重放它们,但是当它到来时异步执行 - 你现在不能这样做。解决方法选项包括:

  1. Use WebDriver Sampler plugin so each JMeter virtual user will kick off a real browser. Warning: this way is very resource intensive.
  2. 使用WebDriver Sampler插件,以便每个JMeter虚拟用户启动真正的浏览器。警告:这种方式非常耗费资源。

  3. Use scripting, i.e. JSR223 PostProcessor to kick off AJAX-driven requests via Apache HttpComponents
  4. 使用脚本,即JSR223 PostProcessor,通过Apache HttpComponents启动AJAX驱动的请求

  5. Develop your custom sampler. You can use the current way of handling embedded resources as a reference.
  6. 开发您的自定义采样器。您可以使用当前处理嵌入资源的方式作为参考。

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

了解更多:如何使用JMeter加载测试启用AJAX / XHR的站点

#4


0  

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.

使用JMeter代理记录采样器后,我遇到了同样的问题。答案在这篇博客文章中:https://lincolnloop.com/blog/load-testing-jmeter-part-1-getting-started/ - 请参阅Ajax请求部分。

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

为ajax请求添加HTTP标头管理器,并确保发送X-Requested-With:XMLHttpRequest标头。