Forum Discussion

dinojadhav's avatar
dinojadhav
Occasional Contributor
5 years ago
Solved

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>
<eb:PartyId eb:type="URI">123123</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId eb:type="URI">99999</eb:PartyId>
</eb:To>
<eb:CPAId>AAS</eb:CPAId>
<eb:ConversationId>test</eb:ConversationId>
<eb:Service eb:type="OTA">CDI</eb:Service>
<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>
<wsse:Security 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>
</wsse:Security>
</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" xmlns:or114="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>
<stl19:SystemCreationTimestamp>2019-05-22T00:30:00</stl19:SystemCreationTimestamp>
<stl19:CreationAgentID>DJL</stl19:CreationAgentID>
<stl19:UpdateTimestamp>2019-05-22T00:30:27</stl19:UpdateTimestamp>
<stl19:PNRSequence>3</stl19:PNRSequence>
<stl19:FlightsRange Start="2019-06-19T22:10:00" End="2019-06-20T06:10:00"/>
<stl19:DivideSplitDetails>
<stl19:DividedRecord>
<stl19:DivideTimestamp>2019-05-22T00:30:00</stl19:DivideTimestamp>
<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>
<stl19:AgentSine>HDQ8DJL</stl19:AgentSine>
</stl19:DividedRecord>
<stl19:SplitToRecord>
<stl19:DivideTimestamp>2019-05-22T00:30:25</stl19:DivideTimestamp>
<stl19:RecordLocator>KYIHBI</stl19:RecordLocator>
<stl19:OriginalNumberOfPax>02</stl19:OriginalNumberOfPax>
<stl19:CurrentNumberOfPax>01</stl19:CurrentNumberOfPax>
<stl19:CurrentPassengerNames>SABRE/PLATINUM</stl19:CurrentPassengerNames>
</stl19:SplitToRecord>
</stl19:DivideSplitDetails>
<stl19:EstimatedPurgeTimestamp>2019-07-19T00:00:00</stl19:EstimatedPurgeTimestamp>
<stl19:UpdateToken>2ce0b4e628e2eb3d47fab119a981d606b654bbc69d326850</stl19:UpdateToken>
</stl19:BookingDetails>
<stl19:POS AirExtras="false" InhibitCode="U">
<stl19:Source BookingSource="A0A0" AgentSine="DJL" PseudoCityCode="HDQ" ISOCountry="US" AgentDutyCode="8" AirlineVendorID="VA" HomePseudoCityCode="HDQ" PrimeHostID="VA"/>
</stl19:POS>
<stl19:PassengerReservation>
<stl19:Passengers>
<stl19:Passenger 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">
<stl19:SupplierCode>VA</stl19:SupplierCode>
<stl19:Number>9290011813</stl19:Number>
<stl19:TierLevelNumber>2</stl19:TierLevelNumber>
<stl19:ShortText>PLT</stl19:ShortText>
<stl19:ReceivingCarrierCode>VA</stl19:ReceivingCarrierCode>
<stl19:StatusCode>HK</stl19:StatusCode>
<stl19:PartnershipAirlineCodes>
<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>
</stl19:PartnershipAirlineCodes>
</stl19:FrequentFlyer>
<stl19:Seats/>
</stl19:Passenger>
</stl19:Passengers>
<stl19:Segments>
<stl19:Poc>
<stl19:Airport>DPS</stl19:Airport>
<stl19:Departure>2019-06-19T22:10:00</stl19:Departure>
</stl19:Poc>
<stl19:Segment 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="**">
<stl19:DepartureAirport>DPS</stl19:DepartureAirport>
<stl19:DepartureAirportCodeContext>IATA</stl19:DepartureAirportCodeContext>
<stl19:ArrivalAirport>SYD</stl19:ArrivalAirport>
<stl19:ArrivalAirportCodeContext>IATA</stl19:ArrivalAirportCodeContext>
<stl19:OperatingAirlineCode>VA</stl19:OperatingAirlineCode>
<stl19:OperatingAirlineShortName>VIRGIN AUSTRALIA</stl19:OperatingAirlineShortName>
<stl19:OperatingFlightNumber>0036</stl19:OperatingFlightNumber>
<stl19:EquipmentType>73H</stl19:EquipmentType>
<stl19:MarketingAirlineCode>VA</stl19:MarketingAirlineCode>
<stl19:MarketingFlightNumber>0036</stl19:MarketingFlightNumber>
<stl19:OperatingClassOfService>Y</stl19:OperatingClassOfService>
<stl19:MarketingClassOfService>Y</stl19:MarketingClassOfService>
<stl19:MarriageGrp>
<stl19:Ind>0</stl19:Ind>
<stl19:Group>0</stl19:Group>
<stl19:Sequence>0</stl19:Sequence>
</stl19:MarriageGrp>
<stl19:Seats/>
<stl19:Eticket>true</stl19:Eticket>
<stl19:DepartureDateTime>2019-06-19T22:10:00</stl19:DepartureDateTime>
<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>
<stl19:SegmentSpecialRequests/>
<stl19:inboundConnection>false</stl19:inboundConnection>
<stl19:outboundConnection>false</stl19:outboundConnection>
<stl19:ScheduleChangeIndicator>false</stl19:ScheduleChangeIndicator>
<stl19:SegmentBookedDate>2019-05-22T00:30:00</stl19:SegmentBookedDate>
<stl19:Pos>
<stl19:IataNumber>0</stl19:IataNumber>
<stl19:AgencyCityCode>HDQ</stl19:AgencyCityCode>
<stl19:CountryCode>US</stl19:CountryCode>
<stl19:DutyCode>8</stl19:DutyCode>
</stl19:Pos>
<stl19:Banner>MARKETED BY VIRGIN AUSTRALIA</stl19:Banner>
<stl19:Informational>false</stl19:Informational>
</stl19:Air>
</stl19:Segment>
</stl19:Segments>
<stl19:TicketingInfo>
<stl19:TicketingTimeLimit id="7" index="1" elementId="pnr-7">
<stl19:Time>TL30</stl19:Time>
</stl19:TicketingTimeLimit>
</stl19:TicketingInfo>
<stl19:ItineraryPricing/>
</stl19:PassengerReservation>
<stl19:ReceivedFrom>
<stl19:Name>QA</stl19:Name>
</stl19:ReceivedFrom>
<stl19:PhoneNumbers>
<stl19:PhoneNumber id="6" index="1" elementId="pnr-6">
<stl19:CityCode>HDQ</stl19:CityCode>
<stl19:Number>594999</stl19:Number>
</stl19:PhoneNumber>
</stl19:PhoneNumbers>
<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/>
<stl19:OpenReservationElements>
<or114:OpenReservationElement id="10" type="FF" elementId="pnr-or-10">
<or114:Loyalty>
<or114:FrequentFlyer>
<or114:ActionCode>HK</or114:ActionCode>
<or114:PreviousActionCode>NN</or114:PreviousActionCode>
<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>
</or114:OpenReservationElement>
</stl19:OpenReservationElements>
</stl19:Reservation>
</stl19:GetReservationRS>
</soap-env:Body>
</soap-env:Envelope>
  • 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
    }

3 Replies

    • dinojadhav's avatar
      dinojadhav
      Occasional Contributor

      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+':DepartureAirport')
      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+':OperatingAirlineCode')
      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+':DepartureDateTime')
      log.info(DepartureDateTime_T)
      def DepartureDateTime=DepartureDateTime_T.substring(0,10)
      log.info(DepartureDateTime)
      context.testCase.testSuite.setPropertyValue('DepartureDateTime',DepartureDateTime)

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        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
        }