问题描述
我正在通过$ {__ threadNum} $ {__ time(ddMMyyyy,)} $ {__ BeanShell(vars.getIteration();,)}的组合生成一些唯一的数字 现在我想在cmeter或jmeter中的txt中写相同的数字。 我为此使用了bean shell后处理器。
解决方法
- Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language
- You should not be inlining JMeter Functions or Variables into Groovy scripts
假设以上几点是相关的Groovy代码段
def first = ctx.getThreadNum()
def second = new java.text.SimpleDateFormat('ddMMyyyy').format(new Date())
def third = vars.getIteration()
new File('myFile.txt') << first << second << third
更多信息:Apache Groovy - Why and How You Should Use It
,使用以下代码:-
int random_var = ${__threadNum}${__time(ddMMyyyy,)}${__BeanShell(vars.getIteration();,)};
f = new FileOutputStream("D:/Output1.csv",true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(random_var);
f.flush();
f.close();
有多种方法,但以上只是一个示例。为了提高性能,建议使用groovy。 其他帮助文章:-https://www.blazemeter.com/blog/saving-data-to-csv-files-with-java-through-jmeter 对于常规检查:-https://stackoverflow.com/questions/51597623/jmeter-jsr223-sampler-unable-to-write-data-to-csv文件