In JMeter and BeanShell, how can I make a variable lowercase?

Walter Spicer picture Walter Spicer · Jan 21, 2011 · Viewed 16k times · Source

In JMeter's User Parameters, how can I make a variable lowercase?

Left column

my_lowercase_variable

Right column

${__BeanShell('${my_variable}'.toLowerCase())}  //fails

or

${__javaScript('${my_variable}'.toLowerCase())}  //fails

Such that ${my_lowercase_variable} is lowercase of ${my_variable}. Tried with quote and without and escaping and such. No luck. Any tricks or tips welcome.

Answer

Walter Spicer picture Walter Spicer · Jan 22, 2011

Note to self.

It turns out to be a two liner in BeanShell Sampler rather than a __BeanShell command. Not exactly in the examples unfortunately.

I added the BeanShell Sampler under the Thread Group, then made a variable. No parameters in the form were required only the two liner script below. As long as I don't change the variable I can copy the data to another variable, change that instead, and then make a Value reference to that wherever needed.

First define a variable in some User Parameters or such ie:

Name: my_initial_reference 
Value: ITS IN CAPS

Add a Bean Sampler under the User Preferences or definition list (just next, it's not a child process)

Put in:

String blah = "${my_initial_reference}"; // 
vars.put("blah", blah.toLowerCase());  //${blah} = "its in caps" now available

Now under that with Name/Value pairs I can map ${blah} as the value to whatever process name requires it.

Note that the Debug response will still show the initial value in caps but you'll also see blah=its in caps which is what I wanted to use.