如何从jmeter的setProperty中的变量传递值

问题描述 投票:0回答:1

我有一个设置线程组,用于设置属性值,在线程组中我使用csv数据集configure中的变量

enter image description here

enter image description here

如果我给出$ {__ setProperty($ {name},_ id.csv)}之类的值,它是有效的,但如果我从数组中取出_id.csv则不会读取该值。

testing properties automation jmeter
1个回答
2
投票

不要将JMeter Functions or Variables内联到Groovy脚本中:

  1. 它可能会解决导致脚本编译失败的问题
  2. 它可能与Groovy GString templates冲突
  3. 它与compilation caching功能冲突

根据JSR223 Sampler文档:

在将脚本字段传递给解释器之前,JMeter处理函数和变量引用,因此引用只会被解析一次。脚本文件中的变量和函数引用将逐字传递给解释器,这可能会导致语法错误。要使用运行时变量,请使用适当的props方法,例如

props.get("START.HMS");

props.put("PROP1","1234");

所以你需要修改你的代码如下:

def name = 'file'
def files = ['_id.csv']
props.put(name, files[0])

查看Apache Groovy - Why and How You Should Use It文章,了解有关JMeter中Groovy脚本的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.