Forum Discussion

schu777's avatar
schu777
Occasional Contributor
2 months ago
Solved

How to set the body of a PUT request through a groovy script?

In my test, I have a GET request to get the current value of a row in the database.  The value is a boolean value that needs to be flipped so an update will happen when the PUT request is done. I'm able to get the value just fine, but I need to create the body in the groovy script.  My issue is how to set the "body" (at least what I consider is the body).

For this screen shot, I need to change the "isRejected" to "false", but to retain the rest of the values.  Perhaps there is another method is to refer to a Properties value instead of setting this body?

Thanks!

  • I figured out this groovy script will do what I need, is it the best way to accomplish it, not for sure since I'm pretty new to testing in SoapUI.

    def isRejectValue = !testRunner.testCase.testSteps['TestStep1'].getPropertyValue("VaribleIsRejectedValue")
    def testSteps = testRunner.testCase.getTestStepList()
    for (runner in testSteps) {
        if (runner.name == 'PUT httpRequest') {
            def propList = runner.getPropertyList()
            for (props in propList) {
                if (props.name == 'Request') {
                    props.value = '[{\r\n      "ObjectId": "58",\r\n      "IsRejected": "'+ isRejectValue +'",\r\n      "LastUpdateDate": "2025-01-08T16:07:23-06:00"\r\n}]'
                }
            }
        }
    }

  • schu777's avatar
    schu777
    Occasional Contributor

    I figured out this groovy script will do what I need, is it the best way to accomplish it, not for sure since I'm pretty new to testing in SoapUI.

    def isRejectValue = !testRunner.testCase.testSteps['TestStep1'].getPropertyValue("VaribleIsRejectedValue")
    def testSteps = testRunner.testCase.getTestStepList()
    for (runner in testSteps) {
        if (runner.name == 'PUT httpRequest') {
            def propList = runner.getPropertyList()
            for (props in propList) {
                if (props.name == 'Request') {
                    props.value = '[{\r\n      "ObjectId": "58",\r\n      "IsRejected": "'+ isRejectValue +'",\r\n      "LastUpdateDate": "2025-01-08T16:07:23-06:00"\r\n}]'
                }
            }
        }
    }