Software Testing is evaluation of the software against requirements gathered from users and system specifications. Testing is conducted at the phase level in software development life cycle.
August 11, 2020
How to Validate response using Groovy Script and Xquery Parameter
Validate Response in SoapUI-
1. Xquery Parameter
2. Groovy Script
This is the web Service which I have used for validating the response. http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
1. Xquery Parameter -
While Running this request "ListContinentsByName", I got multiple values with attribute Code and Name in response.
For X Query we need to run request first.
Click on Assertion Tab.
Click on + Sign to add Assertion then it will open window.
Property Content -> XQuery Match ->ADD
It will give you a XQuery Window to perform operation
Click on Declare button
It will be shown like this-
declare namespace
soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace
m='http://www.oorsprong.org/websamples.countryinfo';
Follow the Code - see below for explanation of code-
<Result>
{
for $x in //m:tContinent
return
<List>
<Code> { $x/*:sCode/text()} </Code>
<Name> {$x/*:sName/text()} </Name>
</List>
}
</Result>
Click on Select from current from Expected result field.
The Output looks like this when you hit the "Select from current" button in Expected result field.
Let's Understand the line of syntax I used to get response with single node with different values.
As with XPath assertions, you'll need to make some namespace declarations; click the Declare button at the top of the editor to let soapUI do this for you.
As SOAP response in XML so we need to follow expression in XML.
With opening bracket tag with respective name followed by For clause - for $x in //m:tContinent
The for clause here, translates to "for each member in the set of element returned by //m:tContinent".
The return clause does the heavy lifting data associated with each element via XPath expression. In our example, $x/*:sCode/text() - return the value of Code element.
* plays node root we can say "m" as well if you see my response Looks like
<m:sCode>CK</m:sCode>
<m:sName>Cook Islands</m:sName>
The text() function simply indicates that you want the the actual inner value (Value between tags).
In Simple words,
//It declares iteration and XPath is where similer nodes are present
for $x in //ns:<XPath>
//It will return all values of the attribute
return {$x/ns:<Attribute>}
2) Groovy Script-
Groovy script code written in java script with give more flexibility in code coverage and modify application according to our perfection.
Go to request -> Right click -> Insert Steps -> Groovy Script -> open Groovy Script
def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
def respsone=groovyUtils.getXmlHolder("ListOfContinentsByName#Response")
// Provide node value using get method
def Code = respsone.getNodeValues("//*:sCode")
def ContinentName = respsone.getNodeValues("//*:sName")
// Printing as a list ISOCode
log.info ISOCode.toString()
//Printing as a list of Name
log.info ContinentName.toString()
// Printing as individual item from Array
for(def var in Code)
log.info var
for(def var in ContinentName)
log.info var
The Output look like below,
Subscribe to:
Post Comments (Atom)
Key concepts in Pipeline
1. Agent- To build your code or deploy your software using azure pipelines, you need at least one agent. Two types of agent- Microsoft host...
-
Author- Who creates the work product and fix the defects Management- Review planning, defining scope, selecting people, checking entry an...
-
There are different components of JMeter are called Elements that serve their own purpose. Thread Group- Thread Groups is a collection of T...
-
Review types -- Informal Review -Generating new ideas or solutions, quickly solving minor problems Walk through - Exchanging ideas about t...
No comments:
Post a Comment
Please let me know if you have any doubts.