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 ma 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.
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 ma 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.
Share Improve this question edited Dec 8, 2012 at 18:38 Bhavik Ambani 6,66715 gold badges58 silver badges87 bronze badges asked Dec 8, 2012 at 18:37 JewelJewel 331 gold badge1 silver badge3 bronze badges 3- 2 Please show us some code. What do you have tried? – Bergi Commented Dec 8, 2012 at 18:44
- Regular expression : for="(.[0-9]*)" – Jewel Commented Dec 8, 2012 at 18:57
- Refrence name: custID Regular expression : for="(.[0-9]*)" template: $1$ and match no. : -1 But if I use ForEach controller to pass custID, It creates multiple requests - total number of custID_matchNr.. But I need to send all custID in single request to set preferences of customers – Jewel Commented Dec 8, 2012 at 19:07
2 Answers
Reset to default 3Hint: you can get number of customer Ids using custID_matchNr
.
So your plete 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());
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.