gpt4 book ai didi

jmeter - 在 jmeter 中加载属性文件,然后将属性值分配给 JMeter 变量

转载 作者:行者123 更新时间:2023-12-02 00:52:14 27 4
gpt4 key购买 nike

我有需要加载属性文件并将 prop 值分配给 JMeter UDV 的情况。

我已经能够成功加载属性文件,但是我无法将 prop 值分配给 UDV

我尝试了以下方法:

  1. 加载包含键值的 prop 文件(即 var_from_prop_file=1000)
  2. 创建 UDV(键名“my.var”和值“${var_from_prop_file}”)

使用调试采样器运行调试脚本,我可以看到分配给值1000var_from_prop_file

但是 my.var 仍然为空(没有值)。我期望使用 my.var = ${var_from_prop_file} 创建 UDV 时,my.var 值也将为 1000,但事实并非如此发生在这里。

我尝试过 __eval 和 __evalVar - 到目前为止没有运气。

是否可以将 jmeter 变量引用到属性文件键?并在其他地方调用变量?

到目前为止,调试采样器 - 看起来像 jmeter 首先加载 UDV,然后加载 jmeter 属性,而不是这样。

最佳答案

你所有的尝试都在获取变量,你需要使用不同的 functions 来获取属性:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

在您的情况下,将 my.var 设置为以下值

${__P(var_from_prop_file)}

或者

${__property(var_from_prop_file)}

类似的结果,只是注意到__P有默认值1

The default value for the property. If omitted, the default is set to "1".

另一个选项是使用 JSR223 Sampler使用 vars 设置变量,使用 props 获取属性:

vars.put("my.var", props.get("var_from_prop_file")); 

关于jmeter - 在 jmeter 中加载属性文件,然后将属性值分配给 JMeter 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50020601/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com