Forum Discussion
Hi Rao, thanks for your response. I wish I had noticed it earlier. Here is sample output:
HTTP/1.1 200 OK
Content-Type: text/xml
Date: Wed, 06 Jan 2016 18:25:00 GMT
Connection: keep-alive
Transfer-Encoding: chunked
PlanID: 50027
Its the PlanID we want as input to the next test step (next step basically will be endpoint like: someEndpoint/updatePlan?PlanId=whatever
Thanks for any response and Happy New Year!
ok, I have figured out how to extract response from a test step. Here is example groovy step that works:
def response = context.expand( '${CreatePID#Response}' )
So, now I have the input I want for my next test step (response). I simply want to be able to do something where the next step corresponds to calling a restful endpoint such as:
someEndpoint/updatePlan?PlanId=response
, where "response" is the value I extracted from the previous step.
So, I would be grateful for anyone who might know how to take that "response" and pass to next step to accomplish what I indicated above in bold. Thanks!
- nmrao9 years agoChampion Level 3
- nmrao9 years agoChampion Level 3
Ok, the value you looking for is not in the response body, but it is in the response headers.
Here is how you can extract it:
- that can be achieved using a separate step like groovy as you mentioned
- also can be achieved without using additional step, by using script assertion, personally prefer this as one step less.
Script Assertion for first REST request step:
/**the below script extracts PlanID http response header value * and set it a test case level property called * PLANID_VALUE_FROM_PREVIOUS_RESPONSE, of course, you may free to choose * any name. Before that it asserts that there is a header exists in * response called PlanID and not null **/ def key = 'PlanID' assert messageExchange.responseHeaders.containsKey(key)==true, "${key} HTTP Header does not present in the response headers" assert null != messageExchange.responseHeaders[key][0], "Header ${key} does not have any value or null" context.testCase.setPropertyValue('PLANID_VALUE_FROM_PREVIOUS_RESPONSE', (messageExchange.responseHeaders[key][0]).toString())
In the next rest request step, you might have a query parameter for PlanID where you define value as ${#TestCase#PLANID_VALUE_FROM_PREVIOUS_RESPONSE}. For more details on this can be found in the documentation, you should be able to define something like either query '1.3. Query Parameters', but value should be property expansion like above.
It may look something like:
EndPoint: yourhostandport
Resource/Method [POST] updatePlan [updatePlan?PlanId=${#TestCase#PLANID_VALUE_FROM_PREVIOUS_RESPONSE}]
- nmrao9 years agoChampion Level 3tclotworthy, have you tried this?
- tclotworthy9 years agoContributor
Rao,
Sorry, I have been caught up in other things today. I should be able to evaluate your latest assertion idea by this afternoon (US EST). Thanks for your patience.
Tim
Related Content
- 9 months ago
Recent Discussions
- 12 hours ago