Forum Discussion

Ramanasaps4hana's avatar
Ramanasaps4hana
Occasional Contributor
5 years ago

How to set Property Value of Sub Node of XML file in SOAP UI?

Hi Team,

 

Thank you very much in advance.

 

I have xml in the below structure and i need to update values to sub nodes using Groovy script to automate the TestScripts.

 

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:inb="http://sap.com/xi/FI-Processing">
<soap:Header/>
<soap:Body>
<inb:OrderItemMessageBulk>
  <MessageHeader>
      <CreationDateTime></CreationDateTime>
  </MessageHeader>
  <OrderItems>
    <MessageHeader>
      <CreationDateTime></CreationDateTime>
    </MessageHeader>
    <OrderItem>
      <DocumentItemID DocumentItemTypeCode="" SendingComponentID="" LogicalSystemID="">       </DocumentItemID>

  </OrderItems>
</inb:OrderItemMessageBulk>
</soap:Body>
</soap:Envelope>

 

How can i set Value of node DocumentItemTypeCode, SendingComponentID and LogicalSystemID in the above XML structure.

 

Kindly guide me to solve the issue.

 

Regards,

Ramana.

    • Ramanasaps4hana's avatar
      Ramanasaps4hana
      Occasional Contributor

      Hi Himanshu,

       

      Thank you very much for your quick response.

       

      I'm very new to Groovy and even looking for proper training too.

      I tried the below logic but not able to traverse till "DocumentItemTypeCode" but i'm able to set value to "DocumentItemID" level.

       

      import static java.util.UUID.randomUUID
      import com.eviware.soapui.support.XmlHolder

      def transactionID = "${java.util.UUID.randomUUID().toString().replaceAll('-','')}"
      def reqOrder = testRunner.testCase.testSuite.testCases["Order"].testSteps["OrderItem"].getPropertyValue("Request")
      def xmlOrder = new XmlHolder(reqOrder)

      xmlOrder.setNodeValue("//inb:OrderItemMessageBulk/OrderItems/OrderItem/DocumentItemID", transactionID)
      xmlOrder.setNodeValue("//inb:OrderItemMessageBulk/OrderItems/OrderItem/DocumentItemID('DocumentItemTypeCode'))", "GENO")

      def xmlOrderNew = xmlOrder.getXml()

       

      Kindly provide me a bit detail logic like what libraries to import and what syntax to be written because once i'm done with traverse till "DocumentItemTypeCode" then only i can be able to complete my work.

       

      Regards,

      Ramana.

  • nmrao's avatar
    nmrao
    Champion Level 3

    It is pretty simple if you use custom properties of test case.

    Change below from

    <DocumentItemID DocumentItemTypeCode="" SendingComponentID="" LogicalSystemID=""> 

    to

    <DocumentItemID DocumentItemTypeCode="${#TestCase#TYPE_CODE}" SendingComponentID="${#TestCase#COMPONENT_ID}" LogicalSystemID="${#TestCase#SYSTEM_ID}"> 

    Define test case level custom properties

    TYPE_CODE

    COMPONENT_ID

    SYSTEM_ID

    and respective values.

    Please refer documentation for the same

    https://www.soapui.org/scripting-properties/property-expansion/

    • Ramanasaps4hana's avatar
      Ramanasaps4hana
      Occasional Contributor

      Hi Rao,

       

      Thanks for your quick response.

       

      Actually i can't do this because i want to use these properties to automate the test cases. So again passing values inside groovy script for each property will be like double work.

       

      actually i tried without Groovy script initially but i'm facing issues in common property passed across test cases.

       

      ex: I have a TestCase Order which has DocumentID field with dynamic value created using formula "${=UUID.randomUUID().toString().replaceAll('-','')}" and the same "DocumentID" i need to pass to the next TestCase Fulfillment automatically in "OriginalItemID" field which i'm not able to pass it from Order to Fulfillment using property Transfer.

       

      Kindly guide me how can i pass a field value across TestCases in same TestSuite.

       

      Or Kindly help e with Groovy script in case not possible without script.

       

      Regards,

      Ramana.

      • nmrao's avatar
        nmrao
        Champion Level 3
        Thumb rule is that each and every test case should be independent.

        Reorganize the tests so that they can be executed without dependency.