How to use two user defined variables for same thread group for HTTP requests(server name or IP)?
ex: I need run my same j meter scripts in two servers(test, production)
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityHow to use two user defined variables for same thread group for HTTP requests(server name or IP)?
ex: I need run my same j meter scripts in two servers(test, production)
In the top level User defined Variables config element declare 1 variable server and assign it a value like ${__P(server,test-server-name)}
and when you run your test from command line you can pass the value that you want to use using the -J argument like -Jserver=production-server-name. For test it will be the test server and for production it will be the production server.
You can do something similar for all environment specific variables.
Refer to __property link for details
IMO you are solving the wrong problem. If you have the same JMX file, differing only in what environment (url) it is running against, the script to write is one that generates a jmx file. There are a lot of ways to do this, but I use the ruby lib ruby-jmeter which allows me to generate a jmx file that will run against a specified environment, with a specified number of threads, duration, etc.
This approach gives you far more flexibility and will absolutely save you time in the long run.
You are making it complicated for nothing. Open a text file, put the 2 addresses in 2 lines, as:
www.test.com
www.production.com
Save it as servers.csv file in the same location where your Jmeter's JMX file. Then add a "CSV Data Set Config" element (Add -> Config Element). In the details fill:
Filename: servers.csv
File encoding:
Variable Names: ServerName
Delimiter:
Allow quoted data?: False
Recycle on EOF?: True
Stop thread on EOF?: False
Sharing mode: All threads
And now, you can add "HTTP Request Defaults" element and put in the "Web Server" frame -> "Serer Name or IP:" : ${ServerName} Or put in every request the same in "Serer Name or IP:".
In this way, using 2 threads, each of them will have the same variable name but different value.