Reputation: 1
In my webservices test plan, I am sending SOAP request for login with username and in the response data it sends back:
- username
- session id (unique value example:12234546)
I want to save that username and session id into a CSV file.
Upvotes: 0
Views: 785
Reputation: 34526
You should use XPath Extractor to extract each one in a variable.
You can use XPathTest in View Results Tree to test the XPath expression on the response.
And you can then serialize variables in CSV by setting in user.properties files:
sample_variables=username,sessionid
Upvotes: 1
Reputation: 1200
You can do that with Beanshell. Something like:
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
Sting username = vars.get("username");
String RegexMethod(String user) {
String regResult = null;
StringBuilder regex = new StringBuilder(",username:\");
regex.append(user).append(",password:\"(.+?)\".");
try {
Pattern pat = Pattern.compile(regex);
Matcher mac = pat.matcher(text);
mac.find();
regResult = mac.group(1);
} catch (Exception e) {
e.printStackTrace();
}
return regResult;
}
String PATH = "/home/username/jmeterFiles/userData.csv";
try {
FileWriter fileWriter = new FileWriter(PATH, true);
fileWriter.append(username);
fileWriter.append(",");
fileWriter.append(RegexMethod(username));
fileWriter.append("\n");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
You can put this in the Beanshell Post-processor and it will write data you want into the file. It maybe needs little tweaking, but you should get point. You will just need to get your regex...
Upvotes: 0