Advanced Assertions in soapUI Presented by Kushan Athukorala
Agenda XPath Match Assertion XQuery Match Asserion Script Assertions WS-Addressing Response Assertion WS-Addressing Request Assertion
XPath Match Assertion Study XPath First
XPath Match Assertion The XPath Match assertion allows specification of an XPath expression to be evaluated against the received response message and compare its result to a predefined value. Expressions can select everything from attribute values, make Boolean evaluations or select the entire response body. XmlUnit is used internally for comparing xml elements, nodes or hierarchies
XPath Assertion Examples Example1 - Validate that the result contains how many hits declare namespace ns1='http://webservices.amazon.com/AWSECommerceService/2005-07-26'; count(//ns1:Item) Example2 - Validate that the ProductGroup element always is "Book“ declare namespace ns1='http://webservices.amazon.com/AWSECommerceService/2005-07-26'; count(//ns1:ProductGroup[text()!='Book']) Example3 -Validate that DetailPageURL always starts with 'http://www.amazon.com/exec/obidos': declare namespace ns1='http://webservices.amazon.com/AWSECommerceService/2005-07-26'; count(//ns1:DetailPageURL) = count(//ns1:DetailPageURL[starts-with(text(), 'http://www.amazon.com/exec/obidos')])
XQuery Match Assertion Study XQuery First
XQuery Match Assertion The XQuery Match assertions is configured exactly like the XPath Math assertion described above. Difference being that the specified expression is evaluated as an XQuery expression instead This assertion is useful when you want to assert a subset of your data and for example not be dependent on other data, the data order, etc
Script Assertion – Using Groovy script editor Script Assertion allows for arbitrary validations Script has access to the following objects: messageExchange : Message Exchange for the current request/response. Gives direct access to message content, HTTP Headers, Attachments, etc. context : TestRunContext running the current TestCase, this will for now always be an instance of WsdlTestRunContext log : a standard log4j Logger object available for logging arbitrary information
Examples Validate a certain response time assert messageExchange.timeTaken < 400 Validate existence of a response HTTP Header assert messageExchange.responseHeaders["x-amz-id-1"] != null Validate the existence of a specific element using GroovyUtils def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder( messageExchange.responseContent ) assert holder["//ns1:RequestId"] != null
WS-Addressing Response Assertion Validates that the response has valid WS-A header properties.
WS-Addressing Request Assertion Validates that the request has valid WS-A header properties
Thank You
USA INDIA SRILANKA UK www.virtusa.com "Virtusa" is a trademark of the company and a registered trademark in the EU and In India. "Productization" is a service mark of the company and a registered service mark in the United States. "vRule" is a service mark of the company. For more information please contact SalesInquiries@virtusa.com © V I r t u s a C o r p o r a t i o n