Ask a Question

Complex Assertion parameterization

SOLVED
Aman85
Occasional Contributor

Complex Assertion parameterization

Hi,

 

How do i assert the airport name where airport code is ANR from the response below.I do not want to use the index but a dynamic value.

Say there are 10 records listed.How do i assert which belongs to airport code ANR

 

<GetAirportInformationByCountryResult><![CDATA[<NewDataSet>
<Table>
<AirportCode>ANR</AirportCode>
<CityOrAirportName>ANTWERP DEURNE</CityOrAirportName>
<Country>Belgium</Country>
<CountryAbbrviation>BE</CountryAbbrviation>
<CountryCode>409</CountryCode>
<GMTOffset>-1</GMTOffset>
<RunwayLengthFeet>4839</RunwayLengthFeet>
</Table>
<Table>
<AirportCode>GNE</AirportCode>
<CityOrAirportName>GHENT</CityOrAirportName>
<Country>Belgium</Country>
<CountryAbbrviation>BE</CountryAbbrviation>
<CountryCode>409</CountryCode>
<GMTOffset>-1</GMTOffset>
<RunwayLengthFeet>2789</RunwayLengthFeet>
<RunwayElevationFeet>34</RunwayElevationFeet>

 

I am using following code to get Airport name value:

import com.eviware.soapui.support.XmlHolder

def resXmlHolder= new XmlHolder(messageExchange.getResponseContentAsXml())
def cData= resXmlHolder.getNodeValue("//*:GetAirportInformationByCountryResult")
def cDataXmlHolder= new XmlHolder(cData)

def CityOrAirportName= cDataXmlHolder.getNodeValue("//CityOrAirportName")

log.info (CityOrAirportName)

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: Complex Assertion parameterization

Looks you are using Script Assertion.

 

Here is the script:

 

//Define expected airport name
def expAirportName = 'ANTWERP DEURNE'

def dataSet = new XmlSlurper().parseText(context.response).'**'.find{ it.name() == 'GetAirportInformationByCountryResult'} as String
def airportName = new XmlSlurper().parseText(dataSet).'**'.find{ it.name() == 'AirportCode' && it == 'ANR'}.parent().CityOrAirportName.text()
log.info "Airport name is ${airportName} where code is ANR"

assert expAirportName == airportName, 'Does not match with expected value'

 



Regards,
Rao.

View solution in original post

5 REPLIES 5
nmrao
Community Hero

Re: Complex Assertion parameterization

Looks you are using Script Assertion.

 

Here is the script:

 

//Define expected airport name
def expAirportName = 'ANTWERP DEURNE'

def dataSet = new XmlSlurper().parseText(context.response).'**'.find{ it.name() == 'GetAirportInformationByCountryResult'} as String
def airportName = new XmlSlurper().parseText(dataSet).'**'.find{ it.name() == 'AirportCode' && it == 'ANR'}.parent().CityOrAirportName.text()
log.info "Airport name is ${airportName} where code is ANR"

assert expAirportName == airportName, 'Does not match with expected value'

 



Regards,
Rao.

View solution in original post

HKosova
Moderator

Re: Complex Assertion parameterization

You can use the XPath Match assertion with this expression:

(saxon:parse(//*:GetAirportInformationByCountryResult))//Table[AirportCode="ANR"]/CityOrAirportName

and expected result

ANTWERP DEURNE

The saxon: parse function parses CDATA into its own node so we can then apply XPath to it. Credit goes to this answer on Stack Overflow: http://stackoverflow.com/questions/25037701/retrieve-node-value-from-xml-response-in-soapui-which-co...


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Aman85
Occasional Contributor

Re: Complex Assertion parameterization

Thank you nmrao,

This worked just fine 🙂

Aman85
Occasional Contributor

Re: Complex Assertion parameterization

 

HKosova
Moderator

Re: Complex Assertion parameterization

Which version of SoapUI are you using? It works for me in SoapUI 5.3.0.

 

Make sure you specify the node name with the namespace prefix:

//*:GetAirportInformationByCountryResult

not

//GetAirportInformationByCountryResult

 

If this does not help, please post the exact response contents and the full error message.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: