Search code examples
jmeterbeanshell

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


I am using the beanshell PostProcesser and comparing two variables and writting output to a csv file but somehow it is now working.Below is my code

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");
 }

does anyone know what am i doing wrong as this is not working.


Solution

  • In your BeanShell Post Processor, implement the below code snippet.

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

    If if statement is true, it will print Matched, else Not a Match.

    Matched

    Not a Match