I have 4 samples:
First one has a response similar to the XML:
<userId>9709262083</userId>
<name>Tom</name>
<relatedTo>9709262080</relatedTo>
<userId>9709262084</userId>
<name>John</name>
<relatedTo>9709262080</relatedTo>
<userId>9709262085</userId>
<name>Michael</name>
<relatedTo>9709262080</relatedTo>
I created special Regular expression extractor to fetch all userIds (-1 as a Match no.) and fetching work correctly.
And I have 3 exact same samples with only one difference in one parameter (${USER_ID_1}
, ${USER_ID_2}
and ${USER_ID_3}
), but I would like to make my solution more generic and work even if I'll don't know the number of users will be in response.
How can I replace these 3 samples with 1 sample in some kind of loop for each element found in Regular Expression Extractor (without knowing an exact number of users).
(I'm using JMeter 3.2, I'm able to bump it to 5.1)
Update:
How about another way, instead of splitting them I would like to use them as a single variable inside sampler.
//e.g. 3 users
"<User><userId>9709262083</userId></User> <User><userId>9709262084</userId></User> <User><userId>97092620835</userId></User>"
//e.g. 2 users
"<User><userId>9709262083</userId></User> <User><userId>9709262084</userId></User>"
The ideal solution would be to create a temp variable and in each step of the for each, I would just add to that variable pattern with my value.
${myVariable} += "<User><userId>${userId}</userId></User>"
and then I can jsut use ${myVariable}