Forum Discussion

schu777's avatar
schu777
Occasional Contributor
12 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 a...
  • schu777's avatar
    12 months ago

    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}]'
                }
            }
        }
    }