venkat sai
venkat sai

Reputation: 465

How to make the search parameters in http request as dynamic in jmeter

http request: http://ipAddress:Port/SomeResource?Param1=value1&Param2=value2&......

so on. This is a http request sample in jmeter that hits a rest api and gets response in JSON format.

Here the challenge is Param1, param2, param3 .... these search parameters number is not constant it may change depending on the call so i am making a csv file that contains rows that contain search parameters in coma separated format.

CSV file is like
param1,param2
param1,param2,param3
param1

I am using a CSV data configure to pull data from the csv file and put it in the http request

enter image description here

And putting this in http request like

enter image description here

Now if the param is null i don't want see this in http request header so how to do this in jmeter.

Upvotes: 0

Views: 832

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  1. Remove all "Parameters" from the HTTP Request, it should be clean

    enter image description here

  2. Add JSR223 PreProcessor as a child of the HTTP Request sampler you would like to parameterize
  3. Put the following code into "Script" area:

    1.upto(4, {
        if (vars.get('param' + "$it") != null) {
            sampler.addArgument(vars.get('param' + "$it"),'someValue')
        }
    })
    
  4. Add JSR223 PostProcessor as a child of the request you would like to parameterize
  5. Put the following code into "Script" area:

    1.upto(4, {
        vars.remove("param" + "$it")
    })
    
  6. That's it, you should now get what you need. You will not see the changes in JMeter GUI, you will only be able to observe them in the runtime using View Results Tree listener

    enter image description here

Upvotes: 1

Related Questions