Reference a variable within a variable in JMeter
Solution 1
I've managed to solve my problem. I've changed the hostname variable value to: ${__evalVar(${localhost})}
, but I've got this error:
ERRROR jmeter.functions.EvalVarFunction: Variables have not yet been defined
So I've moved the hostname variable declaration in a "User defined variable" child node of my Sampler node. That solved it.
Solution 2
To solve this you should use hostname = ${__eval(${localhost})}
http://jmeter.apache.org/usermanual/functions.html#__eval
Carlos' answer has a mistake (which I can't comment on due to rep) as it uses evalVar, this requires as an argument a plain string:
This works: ${__evalVar(localhost)})
This works: ${__eval(${localhost})}
This doesn't work (the current answer): ${__evalVar(${localhost})} http://jmeter.apache.org/usermanual/functions.html#__evalVar
Solution 3
Check this forum: from Blazemeter
For example: getting value of varible "listid_XXX" where the XXX number comes from an index variable:
${__V(listid_${idx1})}
Comments
-
Carlo almost 2 years
I'm working with JMeter. I'd like to specify the test host using user defined variables, like this:
variable name value localhost localhost test 192.168.0.1 hostname ${localhost}
Executing the test, I see that the hostname value is not substituted, and obviously the test fails. I know I can use properties and pass the hostname from the command line, or simply change the hostname value. Is it possible to it like I've explained?
Thanks. -
Aliaksandr Belik about 12 yearsFine that you solved this by yourself. One note: all the UDV elements in a test plan - no matter where they are - are processed at the start, so I could also simply use 2 consequent separate UDV and define in 1st 'localhost' var and in the 2nd - 'hostname' in the way you did.
-
Carlo about 12 yearsThanks, I didn't think about this approach. I like it.
-
raph over 6 yearsTiny thing, but it looks like you have an extra right parenthesis at the end of
This works: ${__evalVar(localhost)})
.