Variable Path Param for REST service testing in Jmeter

None of the solutions worked for me. Here is what I did

  1. Define HTTP request as shown below and add path /api/v2/state/find/${id} to the request
  2. Right click on HTTP request --> Preprocessor -> User Parameters ->Add variable -> input id and it's value
  3. Start HTTP request, this should work

HTTP Request

User Parameters


This question is path parameter related, where the value of the order number is incremented by 1 in each successive request. But I faced a scenario where I got a list of order numbers and I had to make request for those order numbers. So, I am gonna answer this question with respect to that, this solution can be applied in both the scenarios.

What I did is put all the parameter paths in a CSV file, like this -

/my-service/v1/Customer/order/5247710017785924
/my-service/v1/Customer/order/5247710017785976
/my-service/v1/Customer/order/5247710017785984
/my-service/v1/Customer/order/5247710017785991

Then I iterated through the list of paths in the CSHTTPle and made http request to the server. To know how to iterate through the CSV file and make http request in Jmeter, you can check this link:

https://stackoverflow.com/a/47159022/5892553


The good point to start with is putting your initial order value into User Defined Variable

Given start order as "5247710017785924" you need to create an "ordernumber" variable and set it's value to 5247710017785924.

After each request you can increment variable value by adding BeanShell postprocessor to your HTTP Sampler with following code:

long ordernumber = Long.parseLong(vars.get("ordernumber"));
ordernumber++;
vars.put("ordernumber",String.valueOf(ordernumber));

And set ordernumber in your HTTP Sampler path as

/my-service/v1/Customer/order/${ordernumber}

Use JMeter Counter component to increment variable.

Tags:

Java

Rest

Jmeter