Forum Discussion
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!
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
- 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
- tclotworthy9 years agoContributor
Hi Rao,
I was able to get this to work via the Parameter Transfer tool in SoapUI. I had started a separate thread in the SoapUI NG forum here. Thanks for your help. If I can figure out how, I am going to say that this question is answered. Thanks again!
Related Content
- 9 months ago