如何在 JMeter 的 while 循环中使用 CSV 数据集配置? [英] How to use CSV data set config inside a while loop in JMeter?

查看:38
本文介绍了如何在 JMeter 的 while 循环中使用 CSV 数据集配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要针对 5 到 10 个服务器测试相同的一组 url.URL 在 CSV 文件中定义.服务器名称在用户定义的变量配置中定义.

我根据服务器的数量使用 While Controller 来迭代和执行 url 请求.我当前的逻辑定义如下:

线程组虽然控制器计数器(定义服务器数量)While 控制器(内部检查 "${URL}" != "")CSV 数据集配置(停止 EOF 为真)HTTP 采样器(带有 url 数据)

根据逻辑,我的脚本将运行并读取 CSV 文件一次然后停止.它不是在读取外循环.只有内循环并停止.

解决方案

引用自 :)

I need to test the same set of urls against 5 to 10 servers. URLs are defined in the CSV file. Server names are defined in User Defined Variables config.

I'm using While Controller based on the number of servers to iterate and execute the url requests. My current logic is defined as below:

Thread group
  While controller
   Counter (defines number of servers)
   While controller (inner check "${URL}" != "<EOF>")
     CSV Data Set Config (stop EOF is true)
       HTTP Sampler (with url data)

As per the logic my script will run and read the CSV file once and stop. It's not reading the outer loop. Only inner loop and stopped.

解决方案

Quote from JMeter Manual of CSV Data Set:

By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.

Thread groups cannot be nested. So you have to use the threadgroup to iterate in CSV and foreach to iterate in something else. The second option is to generate a CSV with the URL+Server variations, and using simply a single threadgroup to read the CSV.

First option is here.

Iterating URLs outer loop, iterating servers inner loop. You just need a threadgroup and a foreach inside it. See the pictures:

Sample results:

And of course 3 more results...

You can also play with CSVRead function if you have time :)

这篇关于如何在 JMeter 的 while 循环中使用 CSV 数据集配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆