cancel
Showing results for 
Search instead for 
Did you mean: 

How to capture values from a duplicate tags using groovy script

SOLVED
Highlighted
Occasional Contributor

How to capture values from a duplicate tags using groovy script

Hello All,

 

I have a soap response from which I want to capture some values to use it later. I am able to capture the value from the first tag but unable to capture the value from the second tag as the tag has the same name and don't know how to capture values from duplicate tags using Groovy. Below is my response and the duplicate tag is : 

<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>, 
<stl19:RecordLocator>KYIFID</stl19:RecordLocator>
 
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<eb:MessageHeader eb:version="1.0" soap-env:mustUnderstand="1" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader">
<eb:From>
<ebSmiley TongueartyId eb:type="URI">123123</ebSmiley TongueartyId>
</eb:From>
<eb:To>
<ebSmiley TongueartyId eb:type="URI">99999</ebSmiley TongueartyId>
</eb:To>
<eb:CPAId>AAS</eb:CPAId>
<eb:ConversationId>test</eb:ConversationId>
<ebSmiley Frustratedervice eb:type="OTA">CDI</ebSmiley Frustratedervice>
<eb:Action>getReservationRS</eb:Action>
<eb:MessageData>
<eb:MessageId>379170198351950870</eb:MessageId>
<eb:Timestamp>2019-05-22T05:30:35</eb:Timestamp>
<eb:RefToMessageId>mid:20001209-133003-2333@clientofsabre.com</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
<wsseSmiley Frustratedecurity xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/STSA!ICESMSLB\/STS.LB!-3015097586846399859!250344!0</wsse:BinarySecurityToken>
</wsseSmiley Frustratedecurity>
</soap-env:Header>
<soap-env:Body>
<stl19:GetReservationRS Version="1.19.0" xmlns:stl19="http://webservices.sabre.com/pnrbuilder/v1_19" xmlns:ns6="http://services.sabre.com/res/orr/v0" xmlnsSmiley Surprisedr114="http://services.sabre.com/res/or/v1_14" xmlns:raw="http://tds.sabre.com/itinerary" xmlns:ns4="http://webservices.sabre.com/pnrconn/ReaccSearch">
<stl19:Reservation numberInParty="1" numberOfInfants="0" NumberInSegment="1">
<stl19:BookingDetails>
<stl19:Header>PLATINUM</stl19:Header>
<stl19:RecordLocator>KYIFID</stl19:RecordLocator>
<stl19:CreationTimestamp>2019-05-22T00:30:00</stl19:CreationTimestamp>
<stl19Smiley FrustratedystemCreationTimestamp>2019-05-22T00:30:00</stl19Smiley FrustratedystemCreationTimestamp>
<stl19:CreationAgentID>DJL</stl19:CreationAgentID>
<stl19:UpdateTimestamp>2019-05-22T00:30:27</stl19:UpdateTimestamp>
<stl19Smiley TongueNRSequence>3</stl19Smiley TongueNRSequence>
<stl19:FlightsRange Start="2019-06-19T22:10:00" End="2019-06-20T06:10:00"/>
<stl19Smiley Very HappyivideSplitDetails>
<stl19Smiley Very HappyividedRecord>
<stl19Smiley Very HappyivideTimestamp>2019-05-22T00:30:00</stl19Smiley Very HappyivideTimestamp>
<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>
<stl19:AgentSine>HDQ8DJL</stl19:AgentSine>
</stl19Smiley Very HappyividedRecord>
<stl19Smiley FrustratedplitToRecord>
<stl19Smiley Very HappyivideTimestamp>2019-05-22T00:30:25</stl19Smiley Very HappyivideTimestamp>
<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>
<stl19Smiley SurprisedriginalNumberOfPax>02</stl19Smiley SurprisedriginalNumberOfPax>
<stl19:CurrentNumberOfPax>01</stl19:CurrentNumberOfPax>
<stl19:CurrentPassengerNames>SABRE/PLATINUM</stl19:CurrentPassengerNames>
</stl19Smiley FrustratedplitToRecord>
</stl19Smiley Very HappyivideSplitDetails>
<stl19:EstimatedPurgeTimestamp>2019-07-19T00:00:00</stl19:EstimatedPurgeTimestamp>
<stl19:UpdateToken>2ce0b4e628e2eb3d47fab119a981d606b654bbc69d326850</stl19:UpdateToken>
</stl19:BookingDetails>
<stl19Smiley TongueOS AirExtras="false" InhibitCode="U">
<stl19Smiley Frustratedource BookingSource="A0A0" AgentSine="DJL" PseudoCityCode="HDQ" ISOCountry="US" AgentDutyCode="8" AirlineVendorID="VA" HomePseudoCityCode="HDQ" PrimeHostID="VA"/>
</stl19Smiley TongueOS>
<stl19Smiley TongueassengerReservation>
<stl19Smiley Tongueassengers>
<stl19Smiley Tongueassenger id="5" nameType="S" nameId="01.01" nameAssocId="2" elementId="pnr-5.2">
<stl19:LastName>SABRE</stl19:LastName>
<stl19:FirstName>PLATINUM</stl19:FirstName>
<stl19:FrequentFlyer id="10">
<stl19Smiley FrustratedupplierCode>VA</stl19Smiley FrustratedupplierCode>
<stl19:Number>9290011813</stl19:Number>
<stl19:TierLevelNumber>2</stl19:TierLevelNumber>
<stl19Smiley FrustratedhortText>PLT</stl19Smiley FrustratedhortText>
<stl19:ReceivingCarrierCode>VA</stl19:ReceivingCarrierCode>
<stl19Smiley FrustratedtatusCode>HK</stl19Smiley FrustratedtatusCode>
<stl19Smiley TongueartnershipAirlineCodes>
<stl19:Code>AB</stl19:Code>
<stl19:Code>AC</stl19:Code>
<stl19:Code>VX</stl19:Code>
<stl19:Code>CG</stl19:Code>
<stl19:Code>DL</stl19:Code>
<stl19:Code>VA</stl19:Code>
<stl19:Code>GS</stl19:Code>
<stl19:Code>NZ</stl19:Code>
<stl19:Code>HU</stl19:Code>
<stl19:Code>SA</stl19:Code>
<stl19:Code>HX</stl19:Code>
<stl19:Code>EY</stl19:Code>
<stl19:Code>AZ</stl19:Code>
<stl19:Code>HA</stl19:Code>
<stl19:Code>JD</stl19:Code>
<stl19:Code>XR</stl19:Code>
<stl19:Code>MI</stl19:Code>
<stl19:Code>VS</stl19:Code>
<stl19:Code>SQ</stl19:Code>
</stl19Smiley TongueartnershipAirlineCodes>
</stl19:FrequentFlyer>
<stl19Smiley Frustratedeats/>
</stl19Smiley Tongueassenger>
</stl19Smiley Tongueassengers>
<stl19Smiley Frustratedegments>
<stl19Smiley Tongueoc>
<stl19:Airport>DPS</stl19:Airport>
<stl19Smiley Very Happyeparture>2019-06-19T22:10:00</stl19Smiley Very Happyeparture>
</stl19Smiley Tongueoc>
<stl19Smiley Frustratedegment sequence="1" id="3">
<stl19:Air id="3" sequence="1" segmentAssociationId="2" isPast="false" DayOfWeekInd="3" CodeShare="false" SpecialMeal="false" SmokingAllowed="false" ResBookDesigCode="Y" Code="**">
<stl19Smiley Very HappyepartureAirport>DPS</stl19Smiley Very HappyepartureAirport>
<stl19Smiley Very HappyepartureAirportCodeContext>IATA</stl19Smiley Very HappyepartureAirportCodeContext>
<stl19:ArrivalAirport>SYD</stl19:ArrivalAirport>
<stl19:ArrivalAirportCodeContext>IATA</stl19:ArrivalAirportCodeContext>
<stl19Smiley SurprisedperatingAirlineCode>VA</stl19Smiley SurprisedperatingAirlineCode>
<stl19Smiley SurprisedperatingAirlineShortName>VIRGIN AUSTRALIA</stl19Smiley SurprisedperatingAirlineShortName>
<stl19Smiley SurprisedperatingFlightNumber>0036</stl19Smiley SurprisedperatingFlightNumber>
<stl19:EquipmentType>73H</stl19:EquipmentType>
<stl19:MarketingAirlineCode>VA</stl19:MarketingAirlineCode>
<stl19:MarketingFlightNumber>0036</stl19:MarketingFlightNumber>
<stl19Smiley SurprisedperatingClassOfService>Y</stl19Smiley SurprisedperatingClassOfService>
<stl19:MarketingClassOfService>Y</stl19:MarketingClassOfService>
<stl19:MarriageGrp>
<stl19:Ind>0</stl19:Ind>
<stl19:Group>0</stl19:Group>
<stl19Smiley Frustratedequence>0</stl19Smiley Frustratedequence>
</stl19:MarriageGrp>
<stl19Smiley Frustratedeats/>
<stl19:Eticket>true</stl19:Eticket>
<stl19Smiley Very HappyepartureDateTime>2019-06-19T22:10:00</stl19Smiley Very HappyepartureDateTime>
<stl19:ArrivalDateTime>2019-06-20T06:10:00</stl19:ArrivalDateTime>
<stl19:FlightNumber>0036</stl19:FlightNumber>
<stl19:ClassOfService>Y</stl19:ClassOfService>
<stl19:ActionCode>HK</stl19:ActionCode>
<stl19:NumberInParty>1</stl19:NumberInParty>
<stl19Smiley FrustratedegmentSpecialRequests/>
<stl19:inboundConnection>false</stl19:inboundConnection>
<stl19Smiley SurprisedutboundConnection>false</stl19Smiley SurprisedutboundConnection>
<stl19Smiley FrustratedcheduleChangeIndicator>false</stl19Smiley FrustratedcheduleChangeIndicator>
<stl19Smiley FrustratedegmentBookedDate>2019-05-22T00:30:00</stl19Smiley FrustratedegmentBookedDate>
<stl19Smiley Tongueos>
<stl19:IataNumber>0</stl19:IataNumber>
<stl19:AgencyCityCode>HDQ</stl19:AgencyCityCode>
<stl19:CountryCode>US</stl19:CountryCode>
<stl19Smiley Very HappyutyCode>8</stl19Smiley Very HappyutyCode>
</stl19Smiley Tongueos>
<stl19:Banner>MARKETED BY VIRGIN AUSTRALIA</stl19:Banner>
<stl19:Informational>false</stl19:Informational>
</stl19:Air>
</stl19Smiley Frustratedegment>
</stl19Smiley Frustratedegments>
<stl19:TicketingInfo>
<stl19:TicketingTimeLimit id="7" index="1" elementId="pnr-7">
<stl19:Time>TL30</stl19:Time>
</stl19:TicketingTimeLimit>
</stl19:TicketingInfo>
<stl19:ItineraryPricing/>
</stl19Smiley TongueassengerReservation>
<stl19:ReceivedFrom>
<stl19:Name>QA</stl19:Name>
</stl19:ReceivedFrom>
<stl19Smiley TonguehoneNumbers>
<stl19Smiley TonguehoneNumber id="6" index="1" elementId="pnr-6">
<stl19:CityCode>HDQ</stl19:CityCode>
<stl19:Number>594999</stl19:Number>
</stl19Smiley TonguehoneNumber>
</stl19Smiley TonguehoneNumbers>
<stl19:Remarks>
<stl19:Remark index="1" id="12" type="REG" elementId="pnr-12">
<stl19:RemarkLines>
<stl19:RemarkLine>
<stl19:Text>DIVIDED/HDQ8DJL 0030/22MAY19 KYIHBI</stl19:Text>
</stl19:RemarkLine>
</stl19:RemarkLines>
</stl19:Remark>
<stl19:Remark index="2" id="13" type="HS" elementId="pnr-13">
<stl19:RemarkLines>
<stl19:RemarkLine>
<stl19:Text>SPLIT TO/003025/22MAY19 KYIHBI 02/02 01/01 SABRE/PLATINUM</stl19:Text>
</stl19:RemarkLine>
</stl19:RemarkLines>
</stl19:Remark>
</stl19:Remarks>
<stl19:EmailAddresses/>
<stl19Smiley SurprisedpenReservationElements>
<or114Smiley SurprisedpenReservationElement id="10" type="FF" elementId="pnr-or-10">
<or114:Loyalty>
<or114:FrequentFlyer>
<or114:ActionCode>HK</or114:ActionCode>
<or114Smiley TonguereviousActionCode>NN</or114Smiley TonguereviousActionCode>
<or114:Vendor>VA</or114:Vendor>
<or114:ReceivingCarrierCode>VA</or114:ReceivingCarrierCode>
<or114:VitType>2</or114:VitType>
<or114:FrequentFlyerNumber>9290011813</or114:FrequentFlyerNumber>
<or114:Banner>PLATINUM</or114:Banner>
<or114:Tag>PLT</or114:Tag>
</or114:FrequentFlyer>
</or114:Loyalty>
<or114:NameAssociation>
<or114:LastName>SABRE</or114:LastName>
<or114:FirstName>PLATINUM</or114:FirstName>
<or114:Id>2</or114:Id>
<or114:NameRefNumber>01.01</or114:NameRefNumber>
</or114:NameAssociation>
</or114Smiley SurprisedpenReservationElement>
</stl19Smiley SurprisedpenReservationElements>
</stl19:Reservation>
</stl19:GetReservationRS>
</soap-env:Body>
</soap-env:Envelope>
1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

Re: How to capture values from a duplicate tags using groovy script

@dinojadhav ,

 

So to count

<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>, 

<stl19:RecordLocator>KYIFID</stl19:RecordLocator>
You can use count and then iterate the count to each duplicat record. Refer below piece of code for reference:
 
import com.eviware.soapui.support.GroovyUtils
import com.eviware.soapui.support.XmlHolder

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def xmlHolder = groovyUtils.getXmlHolder(xml)
def val = xmlHolder["//*:RecordLocator"]
def count = xmlHolder["count(//*:RecordLocator)"]

for(i=0;i<count.toInteger();i++){
	log.info val[i] // it will print all the values from duplicate RecordLocator tags
}

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

3 REPLIES 3
Super Contributor

Re: How to capture values from a duplicate tags using groovy script

@dinojadhav ,

 

Can you please attach sample code that you are using to fetch values.

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Occasional Contributor

Re: How to capture values from a duplicate tags using groovy script

Hi Himanshu,

 

Here is my groovy code which I am using to capture values :

 

import com.eviware.soapui.support.GroovyUtils
import com.eviware.soapui.support.XmlHolder


//Collecting the variable version
VV=context.testCase.testSuite.project.getPropertyValue("1.19.0") // the “VV” Is the version of getreservation

def response= context.expand('${Get Reservation#response}')
log.info(response)
def xml=new com.eviware.soapui.support.XmlHolder(response)


//DepartureAirport
def DepartureAirport=xml.getNodeValue('//stl'+19+'Smiley Very HappyepartureAirport')
log.info(DepartureAirport)
context.testCase.testSuite.setPropertyValue('DepartureAirport',DepartureAirport)


//ArrivalAirport
def ArrivalAirport=xml.getNodeValue('//stl'+19+':ArrivalAirport')
log.info(ArrivalAirport)
context.testCase.testSuite.setPropertyValue('ArrivalAirport',ArrivalAirport)

//OperatingAirlineCode
def OperatingAirlineCode=xml.getNodeValue('//stl'+19+'Smiley SurprisedperatingAirlineCode')
log.info(OperatingAirlineCode)
context.testCase.testSuite.setPropertyValue('OperatingAirlineCode',OperatingAirlineCode)

//OperatingFlightNumber
def OperatingFlightNumber=xml.getNodeValue('//stl'+19+':MarketingFlightNumber')
log.info(OperatingFlightNumber)
context.testCase.testSuite.setPropertyValue('OperatingFlightNumber',OperatingFlightNumber)

//ClassOfService
def ClassOfService=xml.getNodeValue('//stl'+19+':ClassOfService')
log.info(ClassOfService)
context.testCase.testSuite.setPropertyValue('ClassOfService',ClassOfService)

//BookingStatus
def BookingStatus=xml.getNodeValue('//stl'+19+':ActionCode')
log.info(BookingStatus)
context.testCase.testSuite.setPropertyValue('BookingStatus',BookingStatus)

//ParentPNR

def RecordLocator=xml.getNodeValue('//stl'+19+':RecordLocator')
log.info(RecordLocator)
context.testCase.testSuite.setPropertyValue('RecordLocator',RecordLocator)


//DepartureDate
def DepartureDateTime_T=xml.getNodeValue('//stl'+19+'Smiley Very HappyepartureDateTime')
log.info(DepartureDateTime_T)
def DepartureDateTime=DepartureDateTime_T.substring(0,10)
log.info(DepartureDateTime)
context.testCase.testSuite.setPropertyValue('DepartureDateTime',DepartureDateTime)

Super Contributor

Re: How to capture values from a duplicate tags using groovy script

@dinojadhav ,

 

So to count

<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>, 

<stl19:RecordLocator>KYIFID</stl19:RecordLocator>
You can use count and then iterate the count to each duplicat record. Refer below piece of code for reference:
 
import com.eviware.soapui.support.GroovyUtils
import com.eviware.soapui.support.XmlHolder

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def xmlHolder = groovyUtils.getXmlHolder(xml)
def val = xmlHolder["//*:RecordLocator"]
def count = xmlHolder["count(//*:RecordLocator)"]

for(i=0;i<count.toInteger();i++){
	log.info val[i] // it will print all the values from duplicate RecordLocator tags
}

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

New Here?
Join us and watch the welcome video:
Final Interview in the Series
API_testing_mistake#7
Top Kudoed Authors
Top Kudoed Posts