Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference a variable within a variable in JMeter

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.

like image 470
Carlo Avatar asked Apr 19 '12 08:04

Carlo


3 Answers

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.

like image 126
Carlo Avatar answered Oct 21 '22 05:10

Carlo


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

like image 40
Thelesserknowngiant Avatar answered Oct 21 '22 06:10

Thelesserknowngiant


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})}
like image 33
Shai Alon Avatar answered Oct 21 '22 07:10

Shai Alon