1

I've a variable foobar defined with the value my_value. When the sequence ${foobar} appears within a test component, it is converted into my_value. How can we stop this conversion?

Some examples that do not work:

  • ${foobar} (output is my_value)

  • \${foobar} (output is input)

  • \\${foobar} (output is \my_value)

  • \\\${foobar} (output is input)

  • $\{foobar} (output is input)

  • \$\{foobar} (output is input)

  • \\$\{foobar} (output is input)

  • \\\$\{foobar} (output is input)

  • $\\{foobar} (output is input)

  • \$\\{foobar} (output is input)

  • \\$\\{foobar} (output is input)

  • \\\$\\{foobar} (output is input)

  • $\\\{foobar} (output is input)

  • \$\\\{foobar} (output is input)

  • \\$\\\{foobar} (output is input)

  • \\\$\\\{foobar} (output is input)

  • \$\{foobar\} (output is input)

None of the inputs above produces the output ${foobar}. How can we escape the sequence ${foobar} to avoid it being converted into my_value?

(Note: I know that using BSF string works, e.g. ${__javaScript("\$foobar")} but that's an extremely hacky (and messy) fix.)

2
  • Just to make sure from my end, you want that when you enter '${foobar}' JMeter should take it as '${foobar}' at some places and as variable value at other places, Right?
    – Dhiman
    Oct 5, 2015 at 14:12
  • @Dhiman, A quick example is the output ${foobar} = my_value. I need to be able to produce this output. The closest non-BSF solution I can arrive at is the input \${foobar} = ${foobar}. But it produces the output \${foobar} = my_value instead of the desired output ${foobar} = my_value.
    – Pacerier
    Oct 6, 2015 at 2:50

2 Answers 2

1

Actually there is no way to do it differently. Another non-scripting option is replacing 1st character (which is $) with equivalent provided via __char() function like:

    ${__char(36)}{foobar}=${foobar}

Char function

Also it is not very recommended to use JavaScript (or any other languages except groovy) for scripting as it may become the bottleneck in case of severe loads and ruin your test. So consider using JSR223 Test Elements and make sure that you select "groovy" language in the dropdown.

See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for more details, different scripting engines performance benchmarks, groovy engine installation instructions and scripting best practices.

0

This is the functionality of JMeter (like any other tool) to pass value of parameter when it's related variable is encountered with correct syntax. Even if I use some other tool and syntax of tool says when you encounter '${Firstname}' variable then replace it with its value as bound by the user, it will replace the same no matter whether I want to replace it at that time or not.

But for your issue, you can implement this with the help of 2 variables (if there is a possibility in your script) e.g. use variable ${foobar1} and ${foobar2} and bind only variable ${foobar1} with a CSV file of other parameter but don't bind ${foobar2} with any parameter. Now, use ${foobar1} only at those places in your script where you want to replace it with its value and at other places use ${foobar2}, in this way when your script is executed ${foobar1} will be replaced with the value and ${foobar2} will be used as it is (i.e. your input will be output). When variable is not bound to any value then it will passed as it is to the script during execution in JMeter.

Another way is to use two variables as mentioned above and then bind ${foobar2} with the value ${foobar} i.e. the value of second variable should be ${foobar} in your CSV, so when script is executed ${foobar1} is replaced with actual value and ${foobar2} will be replaced with value ${foobar}.

One more work around for this is possible if you have to achieve this configuration for different HTTP Requests as shown below.

For example: This is what you want to achieve

enter image description here

Then, you need to use the CSV file (variables) only within the HTTP Request scope as shown below.

enter image description here

Note: This will increase your effort, but as said these are the work-arounds which will provide you what you want to achieve without using BSF.

1
  • Hi thanks for the reply. Re paragraph two, do you mean using two variables instead of one? (this cannot work in my actual use case, I'd effectively need to duplicate 80+ variables into 160+ variables....) Re the third solution, within a single request I need to be able to both utilize the variable ${foobar} and escape it, so this workaround is not working as well. Also, re the first paragraph, is there a component that's able to do this?
    – Pacerier
    Oct 6, 2015 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.