12

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
Pankaj
  • 3,512
  • 16
  • 49
  • 83

6 Answers6

13

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}
  • It would be interesting to know what is more resource-demanding: Counter or BeanShell scripting? – olyv Oct 31 '13 at 15:20
8

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

Pavan Jadda
  • 4,306
  • 9
  • 47
  • 79
  • 1
    How does this answer increment the `${id}` variable? The way this is currently written, all requests will just hit `/api/v2/state/find/1`. There is no incrementing happening. – ivandov Apr 27 '23 at 19:33
4

Use JMeter Counter component to increment variable.

ragnor
  • 2,498
  • 1
  • 22
  • 25
3

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

Rito
  • 3,092
  • 2
  • 27
  • 40
3

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}

Roland
  • 758
  • 1
  • 7
  • 13
1

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!!!

Rakesh Balan
  • 151
  • 1
  • 3