在 jmeter 中使用 beanshell 比较两个字符串并将输出写入 csv 文件

compare two strings and write output into a csv file using beanshell in jmeter

我正在使用 beanshell PostProcesser 并比较两个变量并将输出写入 csv 文件但不知何故现在 working.Below 是我的代码

import org.apache.commons.logging;
import java.lang.String.*;

// using regular expression to get Borderid e.g 1234560
String TOID = vars.get("BOrderID");
// file fath to write defined in user defined variables
String fpath = vars.get("write_file_path");
// orderid to search
String SOID = vars.get("orderID");

String DMN = SOID.equals.(TOID);

if (DMN){

  FileWriter fstream = new FileWriter(fpath+"order_Status.csv", true);

  BufferedWriter out = new BufferedWriter(fstream);

  out.write(TOID+","+SOID);

  out.newLine();

  out.flush();

  } else {
   log.info("orders did not match");
 }

有谁知道我做错了什么,因为这不起作用。

更改此行:

String DMN = SOID.equals.(TOID);

对此:

boolean DMN = SOID.equals(TOID);

也考虑切换到 JSR223 PostProcessor and Groovy language as when it comes to high loads Beanshell performance becomes a big question mark. Well-behaved Groovy scripts can be compiled into bytecode,因此 JSR223 测试元素的性能会好得多。

有关详细信息,请参阅 JSR223 Elements JMeter User Manual entry and Groovy Is the New Black 文章。 Groovy 几乎完全 Java 兼容,因此您可以重用现有的 Beanshell 代码。

在您的 BeanShell Post 处理器中,实现以下代码片段。

String a="Test"; 
String b="Test123"; 

if(a.equals(b)) {
    log.info("Matched"); 
} 
else { 
    log.info("Not a Match");
}

如果 if 语句为真,它将打印 Matched,否则 Not a Match.