Anonymous
Anonymous

Reputation: 888

JMeter: How to insert server name/IP dynamically in HTTP Request

I have created JMeter script that need to be used for different environments like Staging, Production, etc. I want to dynamically change the IP address.

Can someone let me know how can I proceed with this?

Upvotes: 1

Views: 3727

Answers (1)

vins
vins

Reputation: 15370

  • Remove all the IP, port, protocol details from the HTTP Sampler.
  • Add HTTP Request Defaults under test plan - in which you can update IP, Port & Protocol details. So, just changing it one place will do for entire test.
  • As you need to change it dynamically, use property file/properties. for example.. (these names can be anything)

    host.ip=10.11.12.13
    host.port=443
    host.protocol=https
    
  • You can pass the properties via command line argument to the test.

    jmeter -n -t /path/to/test.jmx  -l /path/to/result.jtl -Jhost.ip=10.111.12.13 -Jhost.port=443 -Jhost.protocol=https -Jtest.duration=300
    

    J - defines a local JMeter property.

In the test, access these values using ${__P(host.ip)},${__P(host.port)}..etc


If you have a lot of properties, You can have a look at the Property File Reader. I have been using this for a while & I love it.

Advantage is - even in the GUI mode, it will work great.

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

If you use the Property File Reader & pass the property file name itself dynamically, then use

jmeter -n -t /path/to/test.jmx  -l /path/to/result.jtl -Jproperty.file.path=/path/to/file.properties

Then access it using ${__P(property.file.path)} in the File Path.

Upvotes: 1

Related Questions