Contributions
Re: How to pick minimum value of an attribute from soap response and pick next node value based on it
sure, from the posted response minimum value for AmountAfterTax is 144.06 and corresponding to that HotelCodeis 03062 and ChainCode is ABC. Thank you in advance for looking into it.1.8KViews0likes2CommentsHow to pick minimum value of an attribute from soap response and pick next node value based on it
From below response I am trying to pick minimum value of AmountAfterTax and also value of corresponding HotelCode and ChainCode. Response XML - <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/> <soap:Body> <ns2:OTA_HotelAvailRS AltLangID="en" EchoToken="1234" PrimaryLangID="en" RetransmissionIndicator="false" Target="Test"> <ns2:Success/> <ns2:RoomStays> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="193.81" AmountBeforeTax="169.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="296.43" AmountBeforeTax="259.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="BEST" ChainCode="ABC" HotelCode="1234"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="296.42" AmountBeforeTax="268.20" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="373.56" AmountBeforeTax="338.00" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="PLUS" ChainCode="ABC" HotelCode="3456"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="213.61" AmountBeforeTax="191.23" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="452.36" AmountBeforeTax="404.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="BEST" ChainCode="ABC" HotelCode="03154"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="410.08" AmountBeforeTax="359.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="797.42" AmountBeforeTax="699.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="PLUS" ChainCode="ABC" HotelCode="03147"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="368.42" AmountBeforeTax="322.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="479.08" AmountBeforeTax="419.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="BEST" ChainCode="ABC" HotelCode="03133"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="246.86" AmountBeforeTax="219.30" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="403.00" AmountBeforeTax="358.00" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="BEST" ChainCode="ABC" HotelCode="03092"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> <ns2:RoomStay> <ns2:RoomRates> <ns2:RoomRate> <ns2:Rates> <ns2:Rate RateMode="1"> <ns2:Base AmountAfterTax="144.06" AmountBeforeTax="127.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> <ns2:Rate RateMode="2"> <ns2:Base AmountAfterTax="236.38" AmountBeforeTax="209.98" CurrencyCode="USD" DecimalPlaces="2"/> </ns2:Rate> </ns2:Rates> </ns2:RoomRate> </ns2:RoomRates> <ns2:BasicPropertyInfo BrandCode="BEST" ChainCode="ABC" HotelCode="03062"/> <ns2:TPA_Extensions> <ns2:ExchangeRate Percent="1"/> </ns2:TPA_Extensions> </ns2:RoomStay> </ns2:RoomStays> </ns2:OTA_HotelAvailRS> </soap:Body> </soap:Envelope> Below is the code by which I am able to get all the values for AmountAfterTax but sort method is not working and I am unable to fetch the corresponding HotelCode and ChainCode. import groovy.xml.*; def response = testRunner.testCase.getTestStepByName("AreaAvail_2011B").getProperty("Response").getValue() def parsedXml = new XmlSlurper().parseText(response) def amountAfterTax = parsedXml.'**'.findAll {'Base' == it.name()}*.@AmountAfterTax Arrays.sort(amountAfterTax); def minimumAmount = amountAfterTax[0] Thanks in advance for your suggestions.Solved1.8KViews0likes6CommentsRe: Modify Teststep request to add new nodes with attributes using groovy script
Basically null issue was appearing when I am using direct response of first request in place of passing hardcoded xml to add the node, but that is not an issue any more. I wasnt aware about the community best practices and also unaware of the fact the xml request is tightly structured. Anyways I will keep these thing in mind. Thanks for helping me out. Based on your expertise by any chance is it doable?2.5KViews0likes2CommentsRe: Modify Teststep request to add new nodes with attributes using groovy script
I am able to find a work around for null issue however,nmraois there anyway by which I can add these new node as the first child of parent node? As of now it is adding the nodes as the last child nodes - <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opentravel.org/OTA/2003/05"> <soapenv:Header/> <soapenv:Body> <OTA_HotelAvailRQ EchoToken="1234" RateRangeOnly="true" Target="Test" TimeStamp="2006-07-04T09:00:27.1343316+02:00" TransactionIdentifier="b123456789" Version="4.000" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <AvailRequestSegments> <AvailRequestSegment> <HotelSearchCriteria> <Criterion> <RoomStayCandidates> <RoomStayCandidate Quantity="1"> <GuestCounts> <GuestCount AgeQualifyingCode="1" Count="1"/> </GuestCounts> </RoomStayCandidate> <HotelRef ChainCode="ABC" HotelCode="03092"/> <HotelRef ChainCode="ABC" HotelCode="03144"/> </RoomStayCandidates> </Criterion> </HotelSearchCriteria> </AvailRequestSegment> </AvailRequestSegments> </OTA_HotelAvailRQ> </soapenv:Body> </soapenv:Envelope> But I am trying to achieve like below otherwise I am getting an error "cvc-complex-type.2.4.a: Invalid content was found starting with element 'HotelRef'" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opentravel.org/OTA/2003/05"> <soapenv:Header/> <soapenv:Body> <OTA_HotelAvailRQ EchoToken="1234" RateRangeOnly="true" Target="Test" TimeStamp="2006-07-04T09:00:27.1343316+02:00" TransactionIdentifier="b123456789" Version="4.000" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <AvailRequestSegments> <AvailRequestSegment> <HotelSearchCriteria> <Criterion> <HotelRef ChainCode="ABC" HotelCode="03092"/> <HotelRef ChainCode="ABC" HotelCode="03144"/> <RoomStayCandidates> <RoomStayCandidate Quantity="1"> <GuestCounts> <GuestCount AgeQualifyingCode="1" Count="1"/> </GuestCounts> </RoomStayCandidate> </RoomStayCandidates> </Criterion> </HotelSearchCriteria> </AvailRequestSegment> </AvailRequestSegments> </OTA_HotelAvailRQ> </soapenv:Body> </soapenv:Envelope>2.6KViews0likes4CommentsRe: Modify Teststep request to add new nodes with attributes using groovy script
Thank you man, it has solved the issue. Appreciate your quick reply. I have one quick observation. The newly added nodes are not prefixed with "ns:" and rest of the old tags are prefixed with ns in new request xml, because of which my request xml is failing. Any pointer?2.6KViews0likes8CommentsModify Teststep request to add new nodes with attributes using groovy script
Team I am facing an issue where I am able to fetch muliple values of an attibute from reponse using groovy script and want to create new nodes with attributesin next test step request. I have gone throught the earlier post before creating this new post but none of them provide concreate solution. Response XML - <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/> <soap:Body> <ns2:OTA_HotelSearchRS AltLangID="en" EchoToken="20BB36F8AC152AC46E95033289D89328" PrimaryLangID="en" RetransmissionIndicator="false" Target="Test" TimeStamp="2019-04-07T15:35:51.869-07:00" TransactionIdentifier="SmokeTestHotelSearch" TransactionStatusCode="" Version="1.003" xmlns:ns2="http://www.opentravel.org/OTA/2003/05"> <ns2:Success/> <ns2:Properties> <ns2:Property ChainCode="ABC" HotelCode="03062"> <ns2:RelativePosition Distance="3.0" Name="City Center" UnitOfMeasureCode="1"/> </ns2:Property> <ns2:Property ChainCode="ABC" HotelCode="03092"> <ns2:RelativePosition Distance="7.44" Name="City Center" UnitOfMeasureCode="1"/> </ns2:Property> <ns2:Property ChainCode="ABC" HotelCode="03144"> <ns2:RelativePosition Distance="8.04" Name="City Center" UnitOfMeasureCode="1"/> </ns2:Property> </ns2:Properties> </ns2:OTA_HotelSearchRS> </soap:Body> </soap:Envelope> Groovy Script to fetch Hotel code - import groovy.xml.* def response = testRunner.testCase.getTestStepByName("HotelSearch_2011B").getProperty("Response").getValue() def parsedXml = new XmlSlurper().parseText(response) def HotelCodes = parsedXml.'**'.findAll{ it.name() == 'Property' }*.@HotelCode log.info HotelCodes.size() def testStep = context.testCase.getTestStepByName('AreaAvail_2011B') // Parse the request def xml = new XmlSlurper().parseText(testStep.getPropertyValue('request')) for(hotel in HotelCodes) { xml.Criterion.appendNode { HotelRef.@ChainCode="ABC" HotelRef.@HotelCode=hotel } } log.info XmlUtil.serialize(xml) Next Test Step - AreaAvail request xml - before <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opentravel.org/OTA/2003/05"> <soapenv:Header/> <soapenv:Body> <OTA_HotelAvailRQ EchoToken="1234" RateRangeOnly="true" Target="Test" TimeStamp="2006-07-04T09:00:27.1343316+02:00" TransactionIdentifier="b123456789" Version="4.000" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <AvailRequestSegments> <AvailRequestSegment> <HotelSearchCriteria> <Criterion> </Criterion> </HotelSearchCriteria> </AvailRequestSegment> </AvailRequestSegments> </OTA_HotelAvailRQ> </soapenv:Body> </soapenv:Envelope> Output I am trying to get - <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opentravel.org/OTA/2003/05"> <soapenv:Header/> <soapenv:Body> <OTA_HotelAvailRQ EchoToken="1234" RateRangeOnly="true" Target="Test" TimeStamp="2006-07-04T09:00:27.1343316+02:00" TransactionIdentifier="b123456789" Version="4.000" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <AvailRequestSegments> <AvailRequestSegment> <HotelSearchCriteria> <Criterion> <HotelRef ChainCode="ABC" HotelCode="03092"/> <HotelRef ChainCode="ABC" HotelCode="03062"/> <HotelRef ChainCode="ABC" HotelCode="03144"/> </Criterion> </HotelSearchCriteria> </AvailRequestSegment> </AvailRequestSegments> </OTA_HotelAvailRQ> </soapenv:Body> </soapenv:Envelope> I am using soapui opensource.Solved3KViews0likes11Comments