将BSF后处理器中使用的变量用作另一个采样器中的参数 [英] Using variables used in BSF post-processor as a parameter in another sampler
问题描述
我在采样器中添加了BSF后处理器.
后处理器中的脚本是:
I have a BSF post-processor added to a sampler.
The script in the post-processor is:
var array = JSON.parse(prev.getResponseDataAsString());
array.forEach(function(object)
{
OUT.println("patient_id: "+object.patientId);
OUT.println("fname: "+object.fname);
OUT.println("lname: "+object.lname);
});
现在我想使用object.patientId,object.fname,object.lname值作为另一个请求的参数中的参数.
now i want to use object.patientId, object.fname, object.lname values as parameters in another request's parameters.
例如
Thread Group
- Sampler1
BSF Post-Processor
- Sampler2
我要使用Sampler1的BSF Post Processor javascript中的变量作为Sampler2中的参数.有可能吗?
I want to use the variables in the BSF Post Processor's javascript of Sampler1 as parameters in Sampler2. Is that possible?
推荐答案
轻松: BSF PostProcessor 提供对Jmeter变量/属性的读/写访问权限:
Easily: BSF PostProcessor provides read/write access to Jmeter Variables / Properties:
vars-(JMeterVariables)-提供对变量的读/写访问权限: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object()); vars.getObject("OBJ2");
vars - ( JMeterVariables) - gives read/write access to variables: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object()); vars.getObject("OBJ2");
道具-(JMeterProperties-类java.util.Properties)-例如 props.get("START.HMS"); props.put("PROP1","1234");
props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
在最简单的情况下,您可以使用
In the simplest case you can use
vars.put(patientId,object.patientId.toString());
vars.put(fName,object.fname.toString());
vars.put(lName,object.lname.toString());
在您的BSF PostProcessor中
设置变量,然后获得它们的值,如
in your BSF PostProcessor to set the variables, and then get they values like
vars.get("patientId")
或
${patientId}
但是由于您要立即提取foreach循环中的所有记录,因此无法使用这种方式.
But since you are extracting ALL the records in foreach loop at once you cannot use this way.
在这种情况下,您最好使用类似以下的方法:将在foreach循环中提取的所有记录值写入csv文件,然后使用例如 CSV数据集配置,以循环方式读取记录并使用值连同您的Sampler2:
In this case you have to better use something like the following: write all the records values extracted in foreach loop into csv-file, and then use e.g. CSV Data Set Config to read records one-by-one in loop and use values along with your Sampler2:
While Controller
CSV Data Set Config
Sampler 2
...同样,如果我找到另一种更好的方法,我将很高兴知道这一点.
...As well, if I find another, better way, I'll be glad to know about it.
这篇关于将BSF后处理器中使用的变量用作另一个采样器中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!