Search code examples
variablesjmeter

How to automatically loop multiple Ids in Jmeter


I am now trying to use Jmeter.

I have created a http request to receive multiple Ids from one response and used Json extractor to store the Ids.

The stored Ids are like: id_1:1234 id_2:2234 id_3:3234 id_ALL:1234,2234,3234

Now, I would like to use those Ids in another response, but I don't want to configure the variable every time because there are numbers of id_{ascending number}.

example:

url: http://localhost/{id_1} method: GET

url: http://localhost/{id_2} method: GET

url: http://localhost/{id_3} method: GET

I have tried to use User defined variable like: ${id_${counter}}, but it didn't work. How do I get this operation successfully?

Thanks very much.


Solution

  • The easiest is using ForEach Controller configured like:

    once done in the ForEach Controller's child(ren) you will be able to refer the "current" id as ${id}

    enter image description here

    If you want to use the current iteration counter you need to wrap everything into __V() function like:

    enter image description here

    String representation just in case:

    ${__V(id_${__intSum(${__jm__Loop Controller__idx},1,)},)}
    

    More information: Here’s What to Do to Combine Multiple JMeter Variables