JMeter - 在变量中保存属性,但 JMeter 不解析变量

JMeter - saving properties in variables, but JMeter not resolving the variable

我正在使用 JMeter 属性 文件 reader 成功地从文件中获取值。

然后我使用一个简单的 Groovy 片段将这些值保存在变量中。

那么,为什么 JMeter 仍然认为变量未定义?

控制台的输出显示正在存储变量。

for (i in props)    
    if (i.key.startsWith('testData')) {
        vars.put(i.key, i.value)
        log.info(vars.get(i.key))
    }

tigapo.prop:

testData.getUserHistoryPageUsingGETFile=HistoryControllerApi.csv
testData.createBillingUsingPOSTFile=BillingControllerApi.csv
testData.getCreditExchangeInfoUsingGETFile=BillingControllerApi.csv
testData.handleTagDetectionUsingPOSTFile=TagDetectionControllerApi.csv
testData.getSettingsUsingGETFile=SettingsControllerApi.csv
testData.createUserUsingPOSTFile=UserControllerApi.csv

除了一个步骤外,所有步骤都被禁用,没有错误,我在输出中得到了变量。

当我启用一个使用变量的步骤时,显示错误。

这是 CSV 数据配置:


为了让我的评论更容易阅读: 按照建议做了。

并验证了:

但仍然得到:

2022-05-10 16:32:46,656 INFO o.a.j.s.FileServer: Stored: ${testData.getUserUsingGETFile} Alias: ${testData.getUserUsingGETFile}@11286416
2022-05-10 16:32:46,656 ERROR o.a.j.t.JMeterThread: Test failed!
java.lang.IllegalArgumentException: Could not read file header line for file ${testData.getUserUsingGETFile}
    at org.apache.jmeter.services.FileServer.reserveFile(FileServer.java:283) ~[ApacheJMeter_core.jar:5.4.3]
    at org.apache.jmeter.config.CSVDataSet.initVars(CSVDataSet.java:208) ~[ApacheJMeter_components.jar:5.4.3]
    at org.apache.jmeter.config.CSVDataSet.iterationStart(CSVDataSet.java:171) ~[ApacheJMeter_components.jar:5.4.3]
    at org.apache.jmeter.control.GenericController.fireIterationStart(GenericController.java:399) ~[ApacheJMeter_core.jar:5.4.3]
    at org.apache.jmeter.control.GenericController.fireIterEvents(GenericController.java:391) ~[ApacheJMeter_core.jar:5.4.3]
    at org.apache.jmeter.control.GenericController.next(GenericController.java:160) ~[ApacheJMeter_core.jar:5.4.3]
    at org.apache.jmeter.control.LoopController.next(LoopController.java:134) ~[ApacheJMeter_core.jar:5.4.3]
    at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:91) ~[ApacheJMeter_core.jar:5.4.3]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:254) [ApacheJMeter_core.jar:5.4.3]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_311]
Caused by: java.lang.IllegalArgumentException: File ${testData.getUserUsingGETFile} must exist and be readable
testData.getUserUsingGETFile=UserControllerApi.csv

因为CSV数据集配置正在 JSR223预处理器之前被初始化,看看JMeter测试元素execution order:

0. Configuration elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null)
5. Assertions (unless SampleResult is null)
6. Listeners (unless SampleResult is null)

CSV 数据集配置是 configuration element,因此它是 运行。

所以你需要:

  1. 将 JSR223 预处理器转换为 JSR223 Sampler
  2. 放在setUp Thread Group
  3. 下面