AndyHughes
8 years agoRegular Contributor
How do I extract the new resource created via a REST POST for use in a subsequent request?
The API I'm testing is RESTful so I can create a resource such as an account number by sending a POST to AndysAPI/newaccount The code there generates an account number for me based on the details I'...
- 8 years ago
I have a few snippets that you might be able to use for parsing out the data you want. I'm going to have to fudge some of it since I do not know what your raw request looks like.
testStep = context.testCase.testSteps["Test Step Name"]; String request = new String(testStep.testRequest.response.rawResponseData);
// Set up a split-by-newline array for parsing line by line
String [] splitData = request.split("\n");
for (String eachSplit : splitData)
{
if (eachSplit.contains("AndysAPI/newaccount")
{
// Building this off of the example "AndysAPI/newaccount/1234"
// This creates an array with from the string, using "/" as the delimiter
def accountNumber = eachSplit.tokenize("/")[2];
log.info(accountNumber);
}
}That should be enough to get you started.