Search code examples
variablesparametersjmeterescapingbeanshell

Jmeter functions parse string containg $ symbol


I have an array of strings that looks like this. This code is in a beanshell sampler in a setup thread which is why i'm using props.put() instead of vars.put().

String [] priceList = {"$472.56","$432.98","$200.98","$765.32","$233.98"};
props.put("price_list", priceList);

Then the test moves on to the main thread group, where each user is assigned a random value from the array in a beanshell sampler:

var priceList = props.get("price_list");
var priceRandomIndex = ThreadLocalRandom.current().nextInt(0, priceList.length);
vars.put("price", priceList[priceRandomIndex]);

Users then make a post request with "price" as a parameter, referenced as ${price} in the sampler component. Results tree shows that the request is made with incorrect values that look like this:

24233.98 
24765.32 
24472.56 

The problem occurs when Jmeter tries to get ${price} during the request. Log confirms that the variable has the correct value up to that point. I realise that the problem is that the dollar sign makes jmeter call some function on the variable which returns a different value. How can I get the original value when jmeter calls ${price}?


Solution

  • I cannot reproduce your issue using latest JMeter 5.3

    enter image description here

    So I would suggest looking at jmeter.log file for any suspicious entries

    Also since JMeter 3.1 you're supposed to be JSR223 Test Elements and Groovy language for scripting so it would be better to migrate to Groovy as Beanshell has some performance constraints and in case of high loads it might be the cause of unexpected behaviour.