Forum Discussion

allanwiese's avatar
13 years ago

Set a value to an attribute in property transfer

Hi.

I´m trying to set a value to an attribute in a property transfer, but I still didn´t find the right way to write the target XPath.
I´m always getting a "Missing match for target path".

My transfer is bellow:
declare namespace SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace eb="http://www.ebxml.org/namespaces/messageHeader";
declare namespace xlink="http://www.w3.org/1999/xlink";
declare namespace xsd="http://www.w3.org/1999/XMLSchema";
declare namespace xs="http://www.w3.org/2001/XMLSchema";
declare namespace xmlns="http://www.opentravel.org/OTA/2003/05";
/SOAP-ENV:Envelope/SOAP-ENV:Body/OTA_AirLowFareSearchRQ/OriginDestinationInformation/OriginLocation[@LocationCode]


And the request I´m trying to fill is the following:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<OTA_AirLowFareSearchRQ Target="Production" Version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.opentravel.org/OTA/2003/05">
<POS>
<Source PseudoCityCode="XXX">
<RequestorID Type="X.XXX.X" ID="XXX.XX">
<CompanyName Code="XXXXXXXX"/>
</RequestorID>
</Source>
</POS>
<OriginDestinationInformation RPH="1">
<DepartureDateTime>2012-07-20T00:00:00</DepartureDateTime>
<OriginLocation LocationCode="GYN"/>
<DestinationLocation LocationCode="CWB"/>
</OriginDestinationInformation>
<TravelerInfoSummary>
<AirTravelerAvail>
<PassengerTypeQuantity Code="ADT" Quantity="1"/>
</AirTravelerAvail>
<PriceRequestInformation>
<TPA_Extensions>
<Indicators>
<RetainFare Ind="false"/>
<MinMaxStay Ind="true"/>
<RefundPenalty Ind="true"/>
<ResTicketing Ind="true"/>
<TravelPolicy Ind="false"/>
</Indicators>
</TPA_Extensions>
</PriceRequestInformation>
</TravelerInfoSummary>
<TPA_Extensions>
<IntelliSellTransaction Debug="0">
<RequestType Name="XXXXXXX"/>
<ServiceTag Name="XX"/>
<SabreAth Value="" BinarySecToken="" ConversationID=""/>
</IntelliSellTransaction>
</TPA_Extensions>
</OTA_AirLowFareSearchRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Is there a way to set an attribute value by property transfer?
Or even with Grrovy scripts?

Thanks in advance.
  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    Sure. you should use "//" in root node.
    if you would like to use groovy script to set an attribute in custom property. that's no problem to do that. here is a simple example:

    #1:(need to create a script step. note: the script cannot be run directly, if you define testrunner in test suite or test case level, you should run it in test suite or test case respectively)
    import com.eviware.soapui.support.XmlHolder
    def ts = context.getProperty("#TestSuiteRunner#").currentTestCase.testSuite
    def xmlHolder = new XmlHolder(context.expand ('${StepName#Response}')) //populate your test name
    xmlHolder.namespaces['ns1'] = 'http://.............................'
    def node = xmlHolder.getNodeValue("XPath expression") //just like you used in xpath assertion
    ts.setPropertyVaule("node") //set the value in custom properties of test suite level


    Or

    #2:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def ts = testRunner.testCase.testSuite
    def xmlHolder = groovyUtils.getXmlHolder ("StepName#Response") //populate your step name
    xmlHolder.namespaces['ns1'] = 'http://.............................'
    def node = xmlHolder.getNodeValue("XPath expression") //just like you used in xpath assertion
    ts.setPropertyVaule("node") //set the value in custom properties of test suite level




    thanks,
    Aaron