如何在 jmeter 中使用 csv 文件实现多个 http 请求?
How to acheive multiple http requests with csv file in jmeter?
我想通过 csv 文件多次模拟具有 2 个 http 请求和 1 个 http 请求的用户。下面是我的结构
Test Plan
- Thread Group *[No. of threads = 2, Ramp-up = 1, Loop count = 1]*
- - View Results Tree
- - Simple Controller
- - - http request 1
- - - http request 2
- - - while controller *[condition = ${no} (variable from csv file)]*
- - - - http request 3
- - - - CSV Data set Config *[Recycle on EOF = False, Stop on EOF = False, Sharing Mode = All threads] and CSV file has 3 records*
预期:1 位用户应执行
http request 1, http request 2, http request 3, http request 3, http request 3 (since csv has 3 records)
- 如果我保持 在 EOF = False 时回收,在 EOF = False 时停止 它会继续 运行 请求直到脚本结束和数据结束后(即 3行)它开始抛出错误
- 如果我保持 在 EOF = True 时回收,在 EOF = True 时停止 它只为 1 个用户运行并停止。
- 如果我保持 在 EOF = True 时回收,在 EOF = False 时停止 它会继续运行 请求直到脚本结束
- 如果我保持 在 EOF = False 时回收,在 EOF = True 时停止 它只为 1 个用户运行并停止。
但不能按照我的期望进行模拟。任何帮助,将不胜感激。谢谢
有可能实现你的objective
http request 1, http request 2, http request 3, http request 3, http
request 3 (since csv has 3 records)
中使用以下配置
在 While 控制器中设置了以下条件。
${__jexl3("${UNAME}"!="<EOF>")}
其中 UNAME 是列名
由于条件是在 while 控制器中执行的,因此在执行 http 请求 3 之前需要额外的条件检查
请看下面的控件结构。
希望这有用
也可以通过以下修改多次迭代重复测试。添加了一个 JSR223 采样器,用于重置变量并将文本 EOF 添加到 CSV 文件的末尾。
示例 JMeter test plan and CSV file 在 GitHub 中可用。
将您的 While Controller 条件修改为:
${__jexl3("${myVar}" != "<EOF>",)}
将您的 CSV 数据集配置作为 While 控制器的子项并按如下方式配置:
添加If Controller after the CSV Data Set Config and use the same __jexl3() function作为条件:
- 将您的采样器作为 If 控制器的子项
就是这样,您应该能够 运行 您的脚本并获得等于 CSV 文件中行数的执行次数:
我想通过 csv 文件多次模拟具有 2 个 http 请求和 1 个 http 请求的用户。下面是我的结构
Test Plan
- Thread Group *[No. of threads = 2, Ramp-up = 1, Loop count = 1]*
- - View Results Tree
- - Simple Controller
- - - http request 1
- - - http request 2
- - - while controller *[condition = ${no} (variable from csv file)]*
- - - - http request 3
- - - - CSV Data set Config *[Recycle on EOF = False, Stop on EOF = False, Sharing Mode = All threads] and CSV file has 3 records*
预期:1 位用户应执行
http request 1, http request 2, http request 3, http request 3, http request 3 (since csv has 3 records)
- 如果我保持 在 EOF = False 时回收,在 EOF = False 时停止 它会继续 运行 请求直到脚本结束和数据结束后(即 3行)它开始抛出错误
- 如果我保持 在 EOF = True 时回收,在 EOF = True 时停止 它只为 1 个用户运行并停止。
- 如果我保持 在 EOF = True 时回收,在 EOF = False 时停止 它会继续运行 请求直到脚本结束
- 如果我保持 在 EOF = False 时回收,在 EOF = True 时停止 它只为 1 个用户运行并停止。
但不能按照我的期望进行模拟。任何帮助,将不胜感激。谢谢
有可能实现你的objective
中使用以下配置http request 1, http request 2, http request 3, http request 3, http request 3 (since csv has 3 records)
在 While 控制器中设置了以下条件。
${__jexl3("${UNAME}"!="<EOF>")}
其中 UNAME 是列名
由于条件是在 while 控制器中执行的,因此在执行 http 请求 3 之前需要额外的条件检查
请看下面的控件结构。
希望这有用
也可以通过以下修改多次迭代重复测试。添加了一个 JSR223 采样器,用于重置变量并将文本 EOF 添加到 CSV 文件的末尾。
示例 JMeter test plan and CSV file 在 GitHub 中可用。
将您的 While Controller 条件修改为:
${__jexl3("${myVar}" != "<EOF>",)}
将您的 CSV 数据集配置作为 While 控制器的子项并按如下方式配置:
添加If Controller after the CSV Data Set Config and use the same __jexl3() function作为条件:
- 将您的采样器作为 If 控制器的子项
就是这样,您应该能够 运行 您的脚本并获得等于 CSV 文件中行数的执行次数: