Pass auto increment variable in request URL and body if HTTP request in jmeter

Viewed 3811

I am having a endpoint which accepts a auto-increment integer id as part of path param and in request body also there are some keys which accepts that as well.

For example endpoint is http://foo.bar/{id}

And body is

{
 "someid" : someno+{id passed in url},
 "some world :"fixed string" + "id passed in url"
}

I tried using __counter() directly in place of my {id}, but its not working and in when debugging found that its not replacing the value and its coming as literal only.

2 Answers

Add Counter and call the reference name you defined wherever you want.

Allows the user to create a counter that can be referenced anywhere in the Thread Group

There is __counter() function which is generating an incremented number each time it's being called, you can put its declaration into the URL like:

${__counter(FALSE,counter)}

and the JMeter Variable reference into the request body:

{
 "someid" : someno+${counter},
 "some world :"fixed string" + "id passed in url"
}

enter image description here

This way you will get an unique incremented number for each call

enter image description here

More information: How to Use a Counter in a JMeter Test

Related