Pankaj
Pankaj

Reputation: 3664

Variable Path Param for REST service testing in Jmeter

I'm testing RESt service which has path parameter.

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

I want to increment the number by 1 for each request. How to achieve this in Jmeter? Till now i had been passing a fixed path param, therefor our test result were on only one input parameter.

/my-service/v1/Customer/order/5247710017785924

Upvotes: 15

Views: 41302

Answers (6)

Roland
Roland

Reputation: 878

You can use a JMeter Counter:

  1. right click on your Thread Group (under the Test Plan)
  2. select Add–>Config Element–>Counter
  3. set the Starting value (0), Increment (1), Maximum value, Exported Variable Name ("ordernumber")

Then you can use the exported variable name as path param: /my-service/v1/Customer/order/${ordernumber}

Upvotes: 4

Rakesh Balan
Rakesh Balan

Reputation: 179

I used a BeanShell PreProcessor to generate an id

vars.put("id", UUID.randomUUID().toString());

Then used the path Http Request

/api/v1/event/${id}/

BINGO!!!

Upvotes: 1

Pavan Jadda
Pavan Jadda

Reputation: 4871

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

Upvotes: 10

Rito
Rito

Reputation: 3290

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

Upvotes: 3

user2862211
user2862211

Reputation:

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}

Upvotes: 15

ragnor
ragnor

Reputation: 2528

Use JMeter Counter component to increment variable.

Upvotes: 4

Related Questions