3

How to use two user defined variables for same thread group for HTTP requests(server name or IP)?

enter image description here

ex: I need run my same j meter scripts in two servers(test, production)

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked Mar 15, 2017 at 4:07
5
  • Do you mean to say when you run in test use one set of server and and when in production use another? Commented Mar 15, 2017 at 18:31
  • I mean i want to run my test in both servers (server 1,server2) at the same time. Commented Mar 17, 2017 at 6:37
  • any comments pls? Commented Mar 20, 2017 at 15:19
  • You can do that with two separate scripts. One sending traffic to test and another to production. The question i have for you is why do you want to run both the tests at the same time? Commented Mar 20, 2017 at 16:31
  • @ Abhishek Asthana actually I want to maintain only one Script... sorry mistakenly typed that 'same time'. I want to run these scripts after run in Test and then Production.This will be run in server automatically once we set up minimum changes need thats why.. Commented Mar 21, 2017 at 13:54

3 Answers 3

2

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. User Defined Variables You can do something similar for all environment specific variables.

Refer to __property link for details

answered Mar 21, 2017 at 14:04
1

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.

answered Aug 18, 2017 at 18:34
0

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.

answered Jun 19, 2018 at 13:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.