Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter-what is difference between use ${} or vars.get() to get value of variable

Tags:

jmeter

Today when I was debugging my JMeter script, I found a problem that confused me a lot.

  1. CSV Data Config element: in CSV, I set variable userId to 1001200

enter image description here

  1. Then run script below, and get different value of "userId" when using ${userId} and vars.get("userId"). I think they should be same value, but it seems not. After run vars.put("userId", "-111"), ${userId} and vars.get("userId") get different values:

enter image description here

so it seems ${} and vars.get() have some difference even though their variable is same, does anyone know the reason?

Thanks in advance.

like image 897
程江栋 Avatar asked Mar 06 '23 19:03

程江栋


1 Answers

Yes, you need to follow best practices when scripting and avoid using ${value}

When using JSR 223 elements, it is advised to check Cache compiled script if available property to ensure the script compilation is cached if underlying language supports it. In this case, ensure the script does not use any variable using ${varName} as caching would take only first value of ${varName}. Instead use : vars.get("varName")

like image 143
user7294900 Avatar answered Apr 27 '23 01:04

user7294900