Forum Discussion

jpdunn's avatar
jpdunn
Occasional Contributor
13 years ago

Testing with REST, different message bodies?

I'm a fairly new SOAPUI Pro user and need to create a test that sends a REST request multiple times using a POST method with a different message body (or payload) on each iteration. The payload type will always be xml. I'm not sure how to do this or if a groovy script is the best way to do it. Is a property transfer better? Further details below... Help is appreciated.

I thought I would do this in a groovy script, since I wrote a script before that dealt with SOAP messages but this is different. Without an initial message body, I can't retrieve an XMLHolder. I've considered using a root element common to every payload but I don't know how to insert a large block of xml other than as a string. This is a problem because I don't want to embed the block as CDATA. Also, I'm not sure how to remove a large block of xml from the request body.
  • jpdunn's avatar
    jpdunn
    Occasional Contributor
    Okay. I figured out at least one way of doing it (and probably the easiest way). I'm using a PropertyTransfer along with my script. The script includes a testcase property "payload", which is used for the PropertyTransfer source. The PropertyTransfer target is the 'request' property of my REST request.

    def payload = '<foo></foo>'
    testRunner.testCase.setPropertyValue( "payload", payload )
    testRunner.runTestStepByName( "PropertyTransfer 1")
    testRunner.runTestStepByName("Method 1 - Request 1")