Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter insert server name or IP dynamically

Tags:

jmeter

I am trying to create JMeter tests and use the same tests for different environments- QA, Staging, Dev etc. I want to dynamically change the IP address by either changing the CSV File or passing the value through ant script or manually through command prompt. Unfortunately, I haven't been able to do so. The Test doesn't pick up the value from CSV file or from the command prompt.

Can someone please help me.

Thanks in Advance.

like image 699
Chins Avatar asked Jan 24 '11 23:01

Chins


2 Answers

I usually add a HTTP Request Defaults element to the test and change it manually.

Selecting an HTTP Request Defaults

enter image description here

Otherwise for automation, you can modify the jmx file using a script.

Edit in fact, you can use ant filters to change this dynamically at build time. For example, use a filter of <filter token="SERVER" value="${server}"/> and a copy target with filtering on the file below will get you a new jmx file which will use the correct server.

 <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true">
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp name="HTTPSampler.domain">@SERVER@</stringProp>
          <stringProp name="HTTPSampler.port"></stringProp>
          <stringProp name="HTTPSampler.connect_timeout"></stringProp>
          <stringProp name="HTTPSampler.response_timeout"></stringProp>
          <stringProp name="HTTPSampler.protocol"></stringProp>
          <stringProp name="HTTPSampler.contentEncoding"></stringProp>
          <stringProp name="HTTPSampler.path"></stringProp>
        </ConfigTestElement>
like image 156
StevenWilkins Avatar answered Dec 19 '22 02:12

StevenWilkins


First of all, you should place your csv file where you saved your test script file. Normally test script can be saved as with jmx extension and placed your csv file in the same directory of it.

Content of the CSV file as follows:

url;www.test123.com
url;www.test1234.com
url;www.test12345.com

Note that in the Thread Group configuration, thread count must be minimum number of lines in the csv file. According to above CSV file, we should define minimum 3 thread in the Thread Group.

After this configuration, JMeter will automatically call Http Request Defaults configuration everytime when a thread is executed.

CSV Data Set Config

enter image description here

HTTP Request Defaults

enter image description here

HTTP Request (Only Path is set)

enter image description here

Regular Expression Extractor (Optional to find specific response)

enter image description here

Write found regex result to a file (Optional)

enter image description here

Source: http://www.codesenior.com/en/tutorial/JMeter-Dynamically-Change-Server-Name-Using-CSV-Data-File

like image 23
olyanren Avatar answered Dec 19 '22 02:12

olyanren