I have a list of order number's that I have got from one HTTP request.I need to extract all these numbers and use in my next HTTP request passing as an array
2 Answers
Your question is not very clear, in order to provide exact steps we need:
- Full (or partial) response for 1st request
- Exact format of parameter for 2nd request.
In the meantime here is how you can extract the whole response into a JMeter Variable so you will be able to re-use it somewhere else:
- Add Regular Expression Extractor as a child of the request which response you need to extract
Configure it as follows:
- Reference Name: anything meaningful, i.e.
response
- Regular Expression:
(?s)(^.*)
(see How to Extract Data From Files With JMeter article for the regex explanation if needed) - Template:
$1$
- Reference Name: anything meaningful, i.e.
That's it, now you will be able to use the response from the previous request as
${response}
where required.
Step 1: Add a post processor regular expression extractor to your get Http request and extract all order Ids .Use Match no -1 to store all order Ids.Assume that the name of the created variable is "Orders"
Step 2: Add a Beanshell pre-processor to your Post HTTP request and add the following code to the preprocessor
int count = Integer.parseInt(vars.get("Orders_matchNr"));
String delimiter = ",";
StringBuffer sb = new StringBuffer();
for(int i=1;i<=count;i++) {
sb.append(vars.get("Orders_" + i));
if (i == count){
break; //to eliminate comma after the array
}else {
sb.append(delimiter);
}
}
vars.put("arrayOutPut",sb.toString());
use [${arrayOutPut}] to pass as an array
For more information on extracting variables follow this link
-
1