Reputation: 457
100 users will login to https://www.test.com/login Therefore, I created ThreadGroup and set necessary values. Created HTTP Request.
Then, all the users will navigate to SearchInventory https://www.test.com/ SearchInventory -> It will return 1000 items as HTTP response. Each item has Unique SKU Id. Using REGEX and BEAN Shell , I am able to fetch unique Ids from HTTP response and store them in array.
Then, I need to call below HTTP request and pass Unique Item Id to it https://www.test.com/ SearchInventory? itemId = ${itemId} For this, I use For Each loop successfully.
However, now the requirement is that all 100 users can not click on same Item. Each user will hit a unique HTTP request.
For example, user 1 will call HTTP request https://www.test.com/ SearchInventory? itemId = 12100,
User 2 will call https://www.test.com/ SearchInventory? itemId = 12101,
User 3 will call https://www.test.com/ SearchInventory? itemId = 12102 etc.
Like that till user 100
Is there a way to do such things in JMETER ?
In below image, I set Thread Group -> User to 100. In For each loop, I am getting 100 HTTP requests which are dynamically generated by fetching ItemId inside Array from previous HTTP Response. I want one user to hit only 1 request. Another user will call second HTTP requests. However, all thee requests are part of For Each loop because these are dynamically generated. Therefore, for each loop gets executed 100 times for each user.
Upvotes: 0
Views: 372
Reputation: 168207
You need to clarify what form of "array" you're using. For instance, if you initialized an ArrayList like
List myList = new ArrayList();
myList.add("12100");
myList.add("12101");
myList.add("12102");
bsh.shared.myList = myList;
You can access 1st element by 1st virtual user, 2nd element by 2nd virtual user, etc. using __BeanShell function like:
${__BeanShell(bsh.shared.myList.get(ctx.getThreadNum()),)}
Demo:
Also be aware that since JMeter 3.1 it is recommended to use Groovy for any form of scripting so consider migrating to JSR223 Elements and Groovy language on next available opportunity. See Apache Groovy - Why and How You Should Use It article to learn more about Groovy performance and syntax benefits.
Upvotes: 1