agiletestware
14 years agoOccasional Contributor
obtaining request/response for rest/soap steps via groovy
Hello,
I currently print out the request/response after a test case execution for post processing like this
for(st in testRunner.testCase.testStepList)
{
if (st instanceof com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep)
{
log.info("endpoint: " + st.testRequest.getEndpoint())
log.info("soap request: " + st.testRequest.requestContent)
log.info("soap resposne: " + st.testRequest.responseContent)
String assertMessage = ""
for(def i=st.assertionCount-1; i>=0; i--)
{
def a = st.getAssertionAt(i)
assertMessage = assertMessage + a.label + ": " + a.status + "\n"
}
log.info("assertion: " + assertMessage)
}
}
for my sample wsdl, this prints out
Fri Jan 21 06:00:03 PST 2011:INFO:endpoint: https://api.postalmethods.com/PostalWS.asmx
Fri Jan 21 06:00:03 PST 2011:INFO:soap request: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="PostalMethods">
<soap:Header/>
<soap:Body>
<pos:CancelDelivery>
<!--Optional:-->
<pos:Username>gero et</pos:Username>
<!--Optional:-->
<pos:Password>sonoras imperio</pos:Password>
<pos:ID>1</pos:ID>
</pos:CancelDelivery>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:soap resposne: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CancelDeliveryResponse xmlns="PostalMethods">
<CancelDeliveryResult>-3003</CancelDeliveryResult>
</CancelDeliveryResponse>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:assertion: Match content of [CancelDeliveryResult]: FAILED
Contains: VALID
SOAP Response: VALID
Now this works fine if the test case has no data source. However, if there is a datasource loop, then the code above will only print the last thing from the datasource. How can I access the teststep history after execution. I need to print something like this or similar.
Fri Jan 21 06:00:03 PST 2011:INFO:[row1]endpoint: https://api.postalmethods.com/PostalWS.asmx
Fri Jan 21 06:00:03 PST 2011:INFO:[row1]soap request: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="PostalMethods">
<soap:Header/>
<soap:Body>
<pos:CancelDelivery>
<!--Optional:-->
<pos:Username>gero et</pos:Username>
<!--Optional:-->
<pos:Password>sonoras imperio</pos:Password>
<pos:ID>1</pos:ID>
</pos:CancelDelivery>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:soap resposne: [row1]<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CancelDeliveryResponse xmlns="PostalMethods">
<CancelDeliveryResult>-3003</CancelDeliveryResult>
</CancelDeliveryResponse>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:[row1]assertion: Match content of [CancelDeliveryResult]: FAILED
Contains: VALID
SOAP Response: VALID
Fri Jan 21 06:00:03 PST 2011:INFO:[row2]endpoint: https://api.postalmethods.com/PostalWS.asmx
Fri Jan 21 06:00:03 PST 2011:INFO:[row2]soap request: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="PostalMethods">
<soap:Header/>
<soap:Body>
<pos:CancelDelivery>
<!--Optional:-->
<pos:Username>gero et</pos:Username>
<!--Optional:-->
<pos:Password>sonoras imperio</pos:Password>
<pos:ID>1</pos:ID>
</pos:CancelDelivery>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:soap resposne: [row2]<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CancelDeliveryResponse xmlns="PostalMethods">
<CancelDeliveryResult>-3003</CancelDeliveryResult>
</CancelDeliveryResponse>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:[row2]assertion: Match content of [CancelDeliveryResult]: FAILED
Contains: VALID
SOAP Response: VALID
....
Thanks
I currently print out the request/response after a test case execution for post processing like this
for(st in testRunner.testCase.testStepList)
{
if (st instanceof com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep)
{
log.info("endpoint: " + st.testRequest.getEndpoint())
log.info("soap request: " + st.testRequest.requestContent)
log.info("soap resposne: " + st.testRequest.responseContent)
String assertMessage = ""
for(def i=st.assertionCount-1; i>=0; i--)
{
def a = st.getAssertionAt(i)
assertMessage = assertMessage + a.label + ": " + a.status + "\n"
}
log.info("assertion: " + assertMessage)
}
}
for my sample wsdl, this prints out
Fri Jan 21 06:00:03 PST 2011:INFO:endpoint: https://api.postalmethods.com/PostalWS.asmx
Fri Jan 21 06:00:03 PST 2011:INFO:soap request: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="PostalMethods">
<soap:Header/>
<soap:Body>
<pos:CancelDelivery>
<!--Optional:-->
<pos:Username>gero et</pos:Username>
<!--Optional:-->
<pos:Password>sonoras imperio</pos:Password>
<pos:ID>1</pos:ID>
</pos:CancelDelivery>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:soap resposne: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CancelDeliveryResponse xmlns="PostalMethods">
<CancelDeliveryResult>-3003</CancelDeliveryResult>
</CancelDeliveryResponse>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:assertion: Match content of [CancelDeliveryResult]: FAILED
Contains: VALID
SOAP Response: VALID
Now this works fine if the test case has no data source. However, if there is a datasource loop, then the code above will only print the last thing from the datasource. How can I access the teststep history after execution. I need to print something like this or similar.
Fri Jan 21 06:00:03 PST 2011:INFO:[row1]endpoint: https://api.postalmethods.com/PostalWS.asmx
Fri Jan 21 06:00:03 PST 2011:INFO:[row1]soap request: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="PostalMethods">
<soap:Header/>
<soap:Body>
<pos:CancelDelivery>
<!--Optional:-->
<pos:Username>gero et</pos:Username>
<!--Optional:-->
<pos:Password>sonoras imperio</pos:Password>
<pos:ID>1</pos:ID>
</pos:CancelDelivery>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:soap resposne: [row1]<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CancelDeliveryResponse xmlns="PostalMethods">
<CancelDeliveryResult>-3003</CancelDeliveryResult>
</CancelDeliveryResponse>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:[row1]assertion: Match content of [CancelDeliveryResult]: FAILED
Contains: VALID
SOAP Response: VALID
Fri Jan 21 06:00:03 PST 2011:INFO:[row2]endpoint: https://api.postalmethods.com/PostalWS.asmx
Fri Jan 21 06:00:03 PST 2011:INFO:[row2]soap request: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="PostalMethods">
<soap:Header/>
<soap:Body>
<pos:CancelDelivery>
<!--Optional:-->
<pos:Username>gero et</pos:Username>
<!--Optional:-->
<pos:Password>sonoras imperio</pos:Password>
<pos:ID>1</pos:ID>
</pos:CancelDelivery>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:soap resposne: [row2]<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CancelDeliveryResponse xmlns="PostalMethods">
<CancelDeliveryResult>-3003</CancelDeliveryResult>
</CancelDeliveryResponse>
</soap:Body>
</soap:Envelope>
Fri Jan 21 06:00:03 PST 2011:INFO:[row2]assertion: Match content of [CancelDeliveryResult]: FAILED
Contains: VALID
SOAP Response: VALID
....
Thanks