groovysoapui

Get the testcase status in soapui TearDown script


I am trying to get the testcase status in the TearDown script of the same testcase.

I tried multiple approach but nothing works:

Approach 1:

Code:

def testCaseStatus = testRunner.testCase.getTestStepCollection().find { it.testStepResult.status == "FAILED" } ? "FAILED" : "PASSED"
if (testCaseStatus == "FAILED") 
{
     log.info "Test case failed"
    context.testCase.setPropertyValue('testcaseStatus', 'FAIL')
}
else
{
    log.info "Test case passed"
    context.testCase.setPropertyValue('testcaseStatus', 'PASS')
}

Error:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.getTestStepCollection() is applicable for argument types: () values: []

Approach 2:

def testCaseStatus = testRunner.status.toString()

This always shows RUNNING status.

Approach 3:

def testCaseStatus = testRunner.testCase.getTestStepByName("REST Request | Get Person").getStatus()

Error:

ERROR:An error occurred [No signature of method: com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.getStatus() is applicable for argument types: () values: []
    Possible solutions: getClass(), getAt(java.lang.String), getName(), getSettings(), getLabel()], see error log for details

Can someone help with this or Is there any other way to get the testcase status?


Solution

  • according to docs

    context.getTestRunner().getResults().find{ it.getStatus().toString()=='FAILED' }
    

    should do the work.

    https://www.soapui.org/docs/functional-testing/working-with-scripts/

    https://www.soapui.org/apidocs/5.5.0/com/eviware/soapui/model/testsuite/TestCaseRunContext.html