20

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.

4 Answers 4

12

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Fine 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.
Thanks, I didn't think about this approach. I like it.
10

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

1 Comment

Tiny thing, but it looks like you have an extra right parenthesis at the end of This works: ${__evalVar(localhost)}).
2

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

1

New newer versions (from 2.2), you can use ${__V(${...})}/.

Ex: ${__V(${SERVER_CONTEXT})}/rest

As @Alies Belik mentioned, if you get

ERRROR jmeter.functions.EvalVarFunction: Variables have not yet been defined

then define the 2nd variable in next other UDV (User Defined Variables) node.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.