5

How can I declare a variable name by using the value of a property?

For example, I have the property propertyName with the value propertyValue. I want to declare a variable with the name propertyValue.

I've tried like ${${__P(variableName)}} but such constructions doesnt work.

3 Answers 3

10

You may need to evaluate the property name, using the ${__V()} function.

Thus, you'd probably end up with something like ${__V(${__P(propertyName)})} which would only declare a variable with a null value.

Basics on properties & command line:

if you need to pass variables through the command line, properties are indeed the correct choice.

The flag to set a property is -JpropertyName The function to read a property is ${__P(propertyName)}

For full details, see:

http://wiki.apache.org/jakarta-jmeter/JMeterFAQ#How_do_I_pass_parameters_into_my_Test_scripts.3F_I_want_to_be_able_to_use_the_same_script_to_test_with_different_numbers_of_threads_and_loops.2C_and_I_don.27t_want_to_have_to_change_the_script_each_time.

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

5 Comments

I want not to use property value itself, I want to use it's value as a variable name.
Interesting - what are you trying to achieve by doing this?
For instance, using groovy I put some value to a variable which name I want to compose of several part(prefix, name, postfix - all are variables or proerties). So after I run script, i have a new variable, with that name, and I wanna refer to it somewhere in a sampler.
@BlackGaff my value of property changed when converting to user defined variable keep on changing. ${__setProperty(updateid, 2534)}; when converting to variable it is changing to 2535.
The link is dead.
1

Give up using properties files, try using Variables From CSV plugin. It is pretty simple and robust way to have variables loaded from file.

Comments

1

Property files are great!!! For my requirement, I have created a simple config element for JMeter to read property files.

Please check here.

http://www.testautomationguru.com/jmeter-property-file-reader-a-custom-config-element.

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.