Forum Discussion

chioubaca's avatar
chioubaca
Occasional Contributor
12 years ago

Replace complete POST Request XML Content using Groovy scrip

Hi,

I'm sending POST request using SoapUI and I want to replace the current XML content of my request with a String I created using a groovy script.
I've found several ways to update one node value of my request (using getXmlHolder and setNodeValue), but no way to replace the whole xml content of my POST request.

Is there a way to replace the whole content of my xml request with a String ?

Thanks a lot for your answer.
  • nmrao's avatar
    nmrao
    Champion Level 3
    Can you clarify if the below understanding is correct?
    For simplicity, let us say, a test case contains two steps -
    1. groovy script which creates request xml
    2. soap request step which actually has a request

    Now the xml content in step 2 needs to be replaced.

    Based on the above assumptions, it depends how much of the content varies each time.
    case a: if the values to be replaced is still manageable, you can use the properties (testcase, suite, project level - project.setProperty('NODE_VALUE','new value to be replaced in xml content of step2')). Set these property values instead of updating the xml in step 2. And in the xml of step 2 use those properties where soapui takes care while sending the request (<node>${#Project#NODE_VALUE}</node>)

    case b: if the xml content varies too much, unmanageable with properties for each node value, then in the groovy set the whole xml content string to a property like project.setProperty('REQUEST_XML_CONTENT', xmlString). In the step2,
    <envalope>
    <body>
    ${#Project#REQUEST_XML_CONTENT}
    </body>
    </envalope>

    Though never tried this, let me know if this works.
  • chioubaca's avatar
    chioubaca
    Occasional Contributor
    I didn't say it clearly but I am trying to send a POST request to a REST service.
    My POST request contains some parameters AND the xml content that is sent to the service (and that I want to replace).

    As you said, I'm in case b: the xml content varies too much to change eache node value one by one.
    I tried:
    def holder = groovyUtils.getXmlHolder("CreationPOST#Request")
    holder.updateProperty('REQUEST_XML_CONTENT', "test")

    But I get the following error:
    No signature of method: com.eviware.soapui.support.XmlHolder.updateProperty() is applicable for argument types: (java.lang.String, java.lang.String) values: [REQUEST_XML_CONTENT, test]

    ######################

    And when I try:
    project.updateProperty('REQUEST_XML_CONTENT', "test")

    I get: ERROR:groovy.lang.MissingPropertyException: No such property: project for class: Script5


    Any idea ?
  • nmrao's avatar
    nmrao
    Champion Level 3
    Oh ok, that was quick typing.

    Here it goes:
    testRunner.testCase.testSuite.project.setPropertyValue('name','value')
  • chioubaca's avatar
    chioubaca
    Occasional Contributor
    The linked topic answered my question: I can access the request property through this: testRunner.getTestCase().getTestStepByName("TestStepName").getProperty('Request').setValue(xmlValue)

    Thanks a lot
    • NaveenKumar11's avatar
      NaveenKumar11
      Occasional Contributor

      Could you please share full script that you used for replacing complete POST Request XML using groovy.

       

      Thanks in Advance 

      Naveen

      • nmrao's avatar
        nmrao
        Champion Level 3
        NaveenKumar11, instead of reviving a very old post (if you could not get what was suggested in the above answers), suggest you to create a new topic with details as much as possible.