如何在jmeter中用csv $ {__ threadNum} $ {__ timeddMMyyyy,} $ {__ BeanShellvars.getIteration;,}编写代码?

问题描述

我正在通过$ {__ threadNum} $ {__ time(ddMMyyyy,)} $ {__ BeanShell(vars.getIteration();,)}的组合生成一些唯一的数字 现在我想在cmeter或jmeter中的txt中写相同的数字。 我为此使用了bean shell后处理器。

解决方法

  1. Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language
  2. 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();

enter image description here

有多种方法,但以上只是一个示例。为了提高性能,建议使用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文件

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...