Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
10 years ago

Read Test Request assertions with Groovy script

Hello,

Does anyone know how to validate the result of any assertions set in a previous request with a Groovy script?

For example, my project makes a soap call and I have some assertions set in the Test Request for Content Match, HTTP status etc. I then want to run a Groovy step that can evaluate those assertions and make decisions based on their results.

I found a way to read the assertions but not in a way that is useful to me.

assertList = testRunner.getTestCase().getTestStepByName("MyTestStep").getAssertionList().toString()

This produces

Wed Nov 05 13:35:36 MST 2014:INFO:[com.eviware.soapui.impl.wsdl.teststeps.assertions.ProXPathContainsAssertion@5e58e7b5, com.eviware.soapui.impl.wsdl.teststeps.assertions.ProXPathContainsAssertion@1ed44c77, com.eviware.soapui.security.assertion.ValidHttpStatusCodesAssertion@3e82871, com.eviware.soapui.security.assertion.InvalidHttpStatusCodesAssertion@7eb714b7]


I can't find what to do next.

I've been reading lots of forums and can't seem to find anywhere where someone else has tried this before. Any help would be greatly appreciated.

2 Replies

  • jkrier's avatar
    jkrier
    Regular Contributor
    I think I figured it out and I am going to post the script in case anyone else ever looks this up on the forums. It was really simple, I just had to convert the status to a string.

    obj = context.testCase.getTestStepByName("MyTestStep")
    assertions = obj.getAssertionList()
    assertions.each{log.info(it.name + ' --> ' + it.status)
    stat = (it.status).toString()
    if(stat == "FAILED"){
    log.info "FOUND FAILED"
    testRunner.gotoStepByName("NewTestSTep")
    }
    }
  • jkrier's avatar
    jkrier
    Regular Contributor
    I did find something close to what I am trying to do but I still can't really access the assertion results and add logic to my script depending on their value

    obj = context.testCase.getTestStepByName("MyTestStep")
    assertions = obj.getAssertionList()

    assertions.each{
    log.info(it.name + ' --> ' + it.status)
    }

    assertions.each{
    if(it.status == "FAILED"){
    log.info "FOUND FAILED"
    }
    }


    This will return the following to the output

    Wed Nov 05 14:28:48 MST 2014:INFO:Match content of [OrderStatus] --> FAILED
    Wed Nov 05 14:28:48 MST 2014:INFO:Match content of [OrderStatus] --> FAILED
    Wed Nov 05 14:28:48 MST 2014:INFO:Valid HTTP Status Codes --> VALID
    Wed Nov 05 14:28:48 MST 2014:INFO:Invalid HTTP Status Codes --> VALID


    But it does not seem to find the status and print "FOUND FAILED"

    Not sure why it doesn't work