Forum Discussion

schu777's avatar
schu777
Occasional Contributor
2 months ago

Script Assertion - accessing other Test Steps...

In my test steps, I have a GET that retrieves the existing data.  I'm storing the values with a Property Transfer into a Properties step. The value I will be using is "LastUpdateDate"

A groovy script is called to take the value of "IsRejected" and build up the request value for the PUT request that is called after the groovy script.

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

After the PUT request, I do another GET request to get the same one I just updated, to verify the LastUpdateDate is different from the values in Properties.

I'm looking at the Script Assertion to see if I can do the check there so if the lastUpdateDate is the same, it would fail the test.  My issue is how do I get to the "Properties Step" data?

Perhaps there is a better way to accomplish this, but this is the current path I'm going.

Thanks

 

  • Humashankar's avatar
    Humashankar
    Champion Level 3

    Hi schu777 

    You can leverage the Script Assertion feature in SoapUI.

    • By utilizing the testRunner object, you can access data from the "Properties Step" and compare the original LastUpdateDate with the new value retrieved from the current response.
    • By parsing the response JSON, extracting the new LastUpdateDate, and asserting that it has changed.

    Key considerations include ensuring the correct Properties step name, adjusting the JSON parsing if necessary, and understanding that the assertion will fail if the LastUpdateDate remains unchanged.

    // Get the original LastUpdateDate from the Properties step

    def originalLastUpdateDate = testRunner.testCase.getTestStepByName("Properties").getPropertyValue("LastUpdateDate")

    // Get the new LastUpdateDate from the current response

    def responseContent = messageExchange.responseContent

    def responseJson = new groovy.json.JsonSlurper().parseText(responseContent)

    def newLastUpdateDate = responseJson[0].LastUpdateDate

    // Compare the dates

    assert originalLastUpdateDate != newLastUpdateDate, "LastUpdateDate has not changed"

    log.info "LastUpdateDate successfully updated from ${originalLastUpdateDate} to ${newLastUpdateDate}"

    Best Regards