Hi I need to pass the output of BSF sampler as input to the Bean shell pre-processor below are my programs
BSF采样器:
function makeid()
{
var ts = new Date().getTime();
var digits = 10e10;
//var timestamp = ts.toString() + Math.floor(Math.random() *digits ).toString();
var timestamp = new Date().getTime().toString() + Math.floor(Math.random() *digits ).toString();
return timestamp;
}
function test()
{
var uniqueId=makeid();
var numCopies = 20,status = 'done printing',timestampDonePrintingAttr = "timestamp done printing",Title='demo.jpg',Username='keshavka'
date='1429036296',printstatus='OK',time='1429036296';
var joblog = {};
joblog[uniqueId] = {};
joblog[uniqueId]['NumCopies'] = numCopies;
joblog[uniqueId]['Status'] = status;
joblog[uniqueId]['Title'] = Title;
joblog[uniqueId]['Username'] = Username;
joblog[uniqueId]['date'] = date;
joblog[uniqueId]['print status'] = printstatus;
joblog[uniqueId]['time'] = time;
joblog[uniqueId]['timestampDonePrintingAttr'] = new Date().getTime();
//console.log(i);
var json = JSON.stringify(joblog);
return json;
}
Bean Shell计划:
FileWriter fstream = new FileWriter("C:\\apache-jmeter-2.13\\detail_log7.txt",false);
BufferedWriter out = new BufferedWriter(fstream);
out.write(${test});
out.close();
BSF采样器给了我一个JSON,我需要使用Bean shell脚本创建一个文件并向其写入内容。 请通过这个帮助我
答案 0 :(得分:0)
根据BSF Sampler和Beanshell PreProcessor的位置,方法可能会有所不同。
如果Beanshell PreProcessor是BSF采样器的子代 - 由于在采样器之前执行了PreProcessors,它不会发挥作用。
对于其他情况:
如果你看看"脚本"的顶部输入您会看到一些预定义的变量名称,例如ctx
,vars
,props
等。
例如,vars
代表JMeterVariables类实例,因此您可以在BSF Sampler中设置变量并在Beanshell PreProcessor中访问它:
在BSF:
vars.put('json', json);
在Beanshell中:
out.write(vars.get("json"));
如果上述方法无法通过测试计划的屏幕截图帮助更新问题。
NB: