Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter Set Variable as a Property's Default Value

This doesn't seem like a situation that is unique to me, but I haven't been able to find an answer anywhere.

I am attempting to build Jmeter scripts that can be executed both in the GUI and command line. The command line is going to need values to pass into the test cases, but the same test cases need to be executed via the GUI as well. I initially had separate scripts for GUI and command line, but it seemed redundant to have the same test cases duplicated with just a couple parameters changed.

For example, the GUI test case has the Web Server name set to:

<!-- ${ENV} set in User Defined Variables -->
<stringProp name="HTTPSampler.domain">${ENV}</stringProp>

The command line test case uses the following for parameters:

<!-- Define via command line w/ -JCMDDEV -->
<stringProp name="HTTPSampler.domain">${__P(CMDENV)}</stringProp>

Both work for their served purpose, but I want to combine the tests to be easier maintained and to have the ability to run them via GUI or command line.

I got passed one hurdle, which was combining the GUI Variables to be used as well as Properties for the command line by setting the User Defined Variable ${ENV} as the following:

Name    Value
-----   --------
ENV     ${__P(ENV,dev.address.com)}

I am now able to run the same test case via GUI and command line (defining a new environment with -JENV)

I'm not sure if I'm overthinking this, but I want to be able to add a variable to the property default in order to avoid typos, etc while handing it off to others. I tried a few variations that didn't seem to work:

Name    Value
-----   --------
ENV     ${__P(ENV,${__V(DEV)})}
DEV     dev.address.com

This gave me the following Request:

POST http://DEV/servlet

Instead of:

POST http://dev.address.com/servlet

I also tried using:

${__P(ENV,${DEV})}
${__property(ENV,,${__V(DEV)})}
${__property(ENV,,${DEV})}

I was looking into Jmeter nested variables, but it didn't provide any working solutions.

So to my main question, am I able to use variables as the property defaults. If so, how would I achieve that?

like image 547
Boz Avatar asked Feb 03 '15 18:02

Boz


Video Answer


1 Answers

I found a way around this. It's not exactly how I wanted it, but it could work for right now.

I really wanted to keep everything in one place where people had to make edits, but I was able to get the User Defined Variables to work by adding the ${__P(ENV,${DEV})} to the HTTP Request Defaults Web Server Name instead of pre-defining it as a variable.

Now there are two Config Elements that potentially need to be edited with GUI execution, but I think it should work out better in the long run.

like image 128
Boz Avatar answered Oct 28 '22 06:10

Boz