JMeter的Bean Shell脚本问题

时间:2019-04-25 11:04:57

标签: jmeter beanshell

如何获取http请求的响应时间差(例如Request1-响应时间,Response 2 -Response时间)并写入CSV文件?我尝试过,但是正在调用评估外壳错误

long request2 = prev.getTime(); 
// get HTTP Sampler 2 execution time 
long request1 = Long.parseLong(vars.get("LaunchPage")); 
// get HTTP Sampler 1 execution time from variable 
long delta = (request1 - request2); 
// calculate difference 
log.info("Time difference is: " + difference + " ms"); 
// print difference to jmeter.log file 
FileWriter fstream = new FileWriter("E:/Kohls/TestData.csv",true //
    FileOutputStream out = new FileOutputStream("e://delta.csv", true); 
    out.write((String.valueOf(delta)).getBytes("UTF-8"));

1 个答案:

答案 0 :(得分:0)

您应该替换

log.info("Time difference is: " + difference + " ms"); 

作者

log.info("Time difference is: " + delta + " ms"); 

您还可以在Jmeter中使用Filewriter将输出写入到csv文件中。

请检查以下图片以供参考:

enter image description here