To run an assertion on a SOAP response use the following code
def thisTestCase = testRunner.testCase
def thisTestSuite = thisTestCase.getTestSuite();
def thisProject = thisTestSuite.getProject();
def response = thisTestCase.getTestStepByName("Test Request: search").getPropertyValue("response")
log.info("The Value of the response is [$response]");
def responseXML = new groovy.util.XmlParser(false,false).parseText(response);
def price = responseXML['soapenv:Body']['sam:searchResponse']['sam:searchResponse']['item']['price'];
def priceText = price.text();
assert priceText == '1'
Although there is no example of a non-SOAP response. Here is the code to run an assertion on a non-SOAP response
def thisTestCase = testRunner.testCase
def thisTestSuite = thisTestCase.getTestSuite();
def thisProject = thisTestSuite.getProject();
def response = context.expand('${Test Request: search#Response}')
log.info("The Value of the response is [$response]");
def holder = new com.eviware.soapui.support.GroovyUtils(context).getXmlHolder(response)
def price = holder.getNodeValue("//*:price")
assert price == 1;
No comments:
Post a Comment