jmeter - JMeter: Is it possible to add HTTP Request sampler during run?
问题描述
I have an HTTP request that returns a JSON object that contains multiple urls (mostly image resources). I do not know the number of the urls that will be in the response JSON and that number may vary during time. I need to create an HTTP request for each of the urls that i received.
Is it possible to create HTTP Request samplers while running the JMeter flow? Is there a different solution one can advise me to do in order to send HTTP requests to the list of the urls?
Thanks
解决方案
- Add JSON Extractor as a child of the main request and come up with a JSON Path expression to extract links to images and whatever else URLs you would like to hit
- Add ForEach Controller and configure it to read the JMeter Variable reference name from step 1 and set output variable to anything meaningful
- Add HTTP Request sampler as a child of the ForEach Controller and configure it to use the output variable
- That's it, JMeter will trigger a HTTP Request sampler for each URL present in the original JSON
Given you have the following JSON:
{ "urls": [ { "url": "http://example.com" }, { "url": "http://jmeter.apache.org" }, { "url": "http://jmeter-plugins.org" } ] }
You can extract the URLs into JMeter Variables using the following JSON Extractor setup:
it will give you the following JMeter Variables:
url_1=http://example.com url_2=http://jmeter.apache.org url_3=http://jmeter-plugins.org url_matchNr=3
now if you add ForEach Controller and configure it like:
you will be able to refer the URLs as
${current_url}
in the HTTP Request sampler which is the child of the ForEach Controller
推荐阅读
- python - 带有证书 SSLv3 的 URLLib 警报握手失败
- flutter - 颤振倒计时
- python - 无法在 Spyder 上导入 kivy
- python - hspan zorder 在 Seaborn 箱线图中没有得到尊重
- c# - WPF:将 DataGrid FallBackValue 设置为今天的日期
- java - IBM Maximo - 发送 HTML 电子邮件
- ios - Apple Health initHeartBeatSeries , 如何获取 HKHeartbeatSeriesSample?
- c++ - 在 C++ 中基于分隔符(即空格)拆分字符串的简单而优雅的方法
- django - 计算两个 Django 查询的交集:一个聚合,另一个 - 简单
- javascript - Visual Code 键盘快捷键 - 跳过大括号