Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter beanshell string comparison issue

Tags:

jmeter

I am trying the below code in JMeter BeanShell

I need to compare the value of OldT with ${so_tid_1} which is an exact string and not a variable

String OldT = vars.get("OldT"); 
if (OldT.equals("${so_tid_1}")){ 
    vars.put("OldT","ABCD");
}

I have observed that the if condition is not executed even when the value of OldT is received as ${so_tid_1}. But if I change the condition as if(OldT.equals("some string") it works fine and I get the expected output.

Any thoughts on why it is not working?

like image 594
Maniram Avatar asked Oct 19 '22 08:10

Maniram


1 Answers

Just do this:

 String OldT = vars.get("OldT"); // I need to compare the value of OldT  
                                 // with ${so_tid_1} which is an exact 
                                 // string and not a variable
 if (OldT.equals("\${so_tid_1}")){ 
     vars.put("OldT","ABCD");
 }

You need to escape $ sign.

like image 120
UBIK LOAD PACK Avatar answered Oct 22 '22 22:10

UBIK LOAD PACK