【问题标题】:Next line from csv file in Jmeter beanshell scriptJmeter beanshell脚本中csv文件的下一行
【发布时间】:2016-07-11 16:01:20
【问题描述】:

我正在尝试在 JMeter 中创建一个 BeanShell 脚本来创建 XML 消息并将其保存为变量(当然,然后让 SOAP 采样器发送消息,但这并不是重点)。在脚本中,我有一个随机创建几行的循环,关键是脚本的每个循环都会从 CSV 文件中读取一个新行。循环工作正常,但由于某种原因,CSVread next 似乎不起作用,所以每次它只使用 CSV 文件中的同一行。

这是我正在使用的代码:

try{

  //Use a random variable to loop for a random amount of times
  randomnr = vars.get("randomvariable");
  int randomint = Integer.parseInt(randomnr);
  int FiNr = 123456789;

  //I'm using a stringbuilder to create the xml message
  StringBuilder multi =  new StringBuilder();

  for (int i=1; i<randomint; i++){
    multi.append("SomeXML");
    FiNr = ${__CSVRead(data.csv,0)}; //get a line from the csv
    multi.append(""+FiNr);
    multi.append("SomeMoreXML");
    ${__CSVRead(data.csv,next)}; //Go to the next line in the csv - doesn't seem to be working
  }

  vars.put("xmlmessage",multi.toString()); //put all of it in a variable

}
catch(Exception ex){
  log.warn("Something bad happened", ex);
  throw ex;
}

一切正常,只是它没有前进到循环中的下一行。有什么想法吗?

【问题讨论】:

  • 我不熟悉这个函数,所以我不想把这个作为答案,但我会假设你希望 int FiNr = ${__CSVRead(data.csv,0)}; 在你的 for 循环之外并且 ${__CSVRead(data.csv,next)}; 应该是FiNr=${__CSVRead(data.csv,next)};.
  • @RowlandB 感谢您指出这一点,这是一个新手编程错误。不幸的是,它并没有解决 csv 文件的问题。我更新了代码。此外,FiNr=${__CSVRead(data.csv,next)}; 不起作用,因为您需要指定函数返回值的列。

标签: jmeter beanshell


【解决方案1】:

很遗憾,_csvread() 函数无法与 Beanshell 采样器内的循环一起使用。尝试实现jmeter循环控制器并在其下添加__CSVread()函数。

【讨论】:

    猜你喜欢
    • 2017-03-22
    • 2019-09-28
    • 1970-01-01
    • 2018-10-14
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多