user7851946
user7851946

Reputation:

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

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.

Upvotes: 5

Views: 6293

Answers (3)

Siwei
Siwei

Reputation: 21587

4 years passed, I jmeter changed a little, so let me give another detailed answer:

1.create a test plan 2.create a thread group under this test plan enter image description here 3.create a http request under this "thread group"

enter image description here

4.under this "http request", create a "loop controller" enter image description here

5.under this "loop controller", create a "counter" enter image description here

6.run this thread group, and check your web app log:

enter image description here

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168197

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

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58882

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

Upvotes: 4

Related Questions