Ross Ross - 1 month ago 24
Groovy Question

SoapUI Groovy Script, log.info detailed information about test steps run.

I have a Groovy Script in SoapUI that for each TestStep logs weather that step has passed or failed. I would like the Groovy Script to log the assertion message of what went wrong as well.

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each{
// check that testStep has assertionStatus
// (for example groovy testSteps hasn't this property since
// there is no asserts on its)
if(it.metaClass.hasProperty(it,'assertionStatus')){
if(it.assertionStatus == AssertionStatus.FAILED){
log.info "${it.name} FAILED"

}else if(it.assertionStatus == AssertionStatus.VALID){
log.info "${it.name} Passed"
}else if(it.assertionStatus == AssertionStatus.UNKNOWN){
log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
}
}
}


At the moment I get this output:

Thu Oct 20 11:31:06 BST 2016:INFO:TestStep_0051 Passed
Thu Oct 20 11:31:06 BST 2016:INFO:TestStep_0052 FAILED
Thu Oct 20 11:31:06 BST 2016:INFO:TestStep_0053 Passed


I would like the failed Assertion to display the message why it failed with more detail. It the failed TestStep itself I get the message:

assert node.toString().matches("(0|175.238|0)\\d*") | | | | | false | 132.497286826667 132.497286826667


Also, when I run this Groovy Script, a window pops up that is titled 'Information' which just has a black background and so wide i cant seem to find the right side of it. Does anyone know what this is?

Answer

You can try modifying your code a bit, let me explain:

Instead of access only the final AssertionStatus for the testStep result though metaClass you can access all the assertions for a testStep using getAssertionList(), to avoid problems for testSteps which not contains assertions you can check that this method exists using metaClass.

Then for each assertion on this list, you can check the status and for ones which fails you can get the error message using getErrors() method.

Finally to avoid the prompt message which is produced because by default Groovy returns the last instantiation object (in your script StepList) and SOAPUI prompt it, you can add a return statement to return nothing and avoid the prompt effect.

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each{

    // check that this kind of testStep
    // can contain assertions (avoid errors with groovy testSteps)
    if(it.metaClass.respondsTo(it,"getAssertionList")){

         def assertions = it?.getAssertionList()

         assertions?.each{ assertion ->

            if(assertion?.getStatus() == AssertionStatus.FAILED){
              log.info "${it.name} FAILED"
               assertion?.getErrors()?.each{ error ->
                 log.info "Error message ${error.getMessage()}"
               }
            }else if(assertion?.getStatus() == AssertionStatus.VALID){
                log.info "${it.name} Passed"
            }else if(assertion?.getStatus() == AssertionStatus.UNKNOWN){
                log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
            }
         }
     }
}
return