Forum Discussion

schu777's avatar
schu777
Occasional Contributor
9 months ago
Solved

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 s...
  • Humashankar's avatar
    8 months ago

    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