Reputation: 33
What I have to do:
1. Extract all customer ids from previous response.
2. Shuffle all ids.
3. Pass all ids in one request. (like : custPref - 9768,7651,3215,....)
I took all customer ids in one variable (custID) using regular expression (with set match no. = -1)
By using For Each controller, I am able to pass one customer id in one request.
But now I have to pass all customer ids in one request to set the preferences of customers after shuffle the customer ids with comma separated values.
Also, count of customer Ids are not fixed so could not use variable as ${custID}_g1, ${custID}_g0...
Can you please suggest any way to shuffle customer ids and pass all ids in one request.
Upvotes: 3
Views: 10204
Reputation: 335
If you need to pass array of ints via jmeter to web method, or something similar, here is the solution!
In http request use Post Body.
In post body you need to pass json! Like so: {"language":"en", "translationIds":[10254, 3071, 3072, 3073, 3074, 3075, 3076, 3077, 3078, 3079, 3080, 3081, 3082, 3083, 3084, 3085, 3086, 3087, 3088, 3089, 3090, 3091, 3092, 3093, 3094, 3095, 3096, 3097, 3098, 3099, 3100, 3101, 3102, 3103, 3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111, 3112, 3113, 3114, 3115, 3116, 3117, 3118, 3513]}"
You need HTTP Header Manager with: Content-Type application/json
(CODE) 4. And final you need to place [ScriptService] attribute (C#) on the class that contains the method.
Upvotes: 0
Reputation: 21096
Hint: you can get number of customer Ids using custID_matchNr
.
So your complete Beanshell script may look like:
import java.util.ArrayList;
import java.util.Collections;
ids = new ArrayList();
idCount = Integer.parseInt(vars.get("custID_matchNr"));
for (int i=0; i<idCount; i++){
ids.add(vars.get("custID_" + String.valueOf(i+1)));
}
Collections.shuffle(ids);
builder = new StringBuilder();
for (String id: ids){
builder.append(id);
builder.append(",");
}
builder.deleteCharAt(builder.length()-1);
vars.put("custPref", builder.toString());
Upvotes: 3