如何在 JMeter 中将变量从一个线程组传递到另一个线程组 [英] How do I pass a variable from one Thread Group to another in JMeter

查看:41
本文介绍了如何在 JMeter 中将变量从一个线程组传递到另一个线程组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 2 个线程组的 JMeter 测试——第一个是单线程(创建一些库存),第二个有多个线程(购买所有库存).我使用 BeanShell Assertions 和 XPath Extractors 来解析返回值(即 XML)并存储变量(例如要购买的商品的 id).

I have a JMeter test with 2 Thread Groups - the first is a single thread (which creates some inventory) and the second has multiple threads (which purchase all the inventory). I use BeanShell Assertions and XPath Extractors to parse the returned value (which is XML) and store variables (such as the ids of the items to be purchased).

但是,在第一个线程组中创建的值,无论是提取到标准的 ${jmeter} 类型变量,还是 ${__BeanShell(vars.get("jmeter"))} 类型变量,在第二个线程组中不可用.无论如何要在第一个线程组中创建一个变量并使其对第二个线程组可见?

But, values that are created in the first Thread Group, whether extracted into standard ${jmeter} type variables, or ${__BeanShell(vars.get("jmeter"))} type vars, are not available in the second Thread Group. Is there anyway to create a variable in the first Thread Group and make it visible to the second?

推荐答案

我无法使用变量来做到这一点(因为这些变量对于单个线程来说是本地的).但是,我能够通过属性解决这个问题!

I was not able to do this with variables (since those are local to individual threads). However, I was able to solve this problem with properties!

同样,我的第一个 ThreadGroup 完成了所有设置,我需要该工作中的一些信息可用于第二个 ThreadGroup 中的每个线程.我在第一个 ThreadGroup 中有一个 BeanShell 断言,内容如下:

Again, my first ThreadGroup does all of the set up, and I need some information from that work to be available to each of the threads in the second ThreadGroup. I have a BeanShell Assertion in the first ThreadGroup with the following:

${__setProperty(storeid, ${storeid})};

${storeid} 是使用 XPath Extractor 提取的.BeanShell Assertion 会做其他事情,比如检查 storeid 是否是从前一次调用中返回的,等等.

The ${storeid} was extracted with an XPath Extractor. The BeanShell Assertion does other stuff, like checking that storeid was returned from the previous call, etc.

无论如何,在第二个线程组中,我可以使用 Samplers 中storeid"属性的值,如下所示:

Anyway, in the second ThreadGroup, I can use the value of the "storeid" property in Samplers with the following:

${__property(storeid)}

就像一个魅力!

这篇关于如何在 JMeter 中将变量从一个线程组传递到另一个线程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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