如何在JMeter中将变量从一个线程组传递到另一个线程组 [英] How do I pass a variable from one Thread Group to another in 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 Assertion,其中包含以下内容:
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})};
使用XPath Extractor提取$ {storeid}。 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.
无论如何,在第二个ThreadGroup中,我可以使用采样器中的storeid属性具有以下内容:
Anyway, in the second ThreadGroup, I can use the value of the "storeid" property in Samplers with the following:
${__property(storeid)}
像魅力一样工作!
这篇关于如何在JMeter中将变量从一个线程组传递到另一个线程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!