compare line by line failed teststep response to a teststep "assertion contains" using groovy script soapui

615 views Asked by At

I've been searching for a way to compare the response of a failed test step to the "contains" assertion of that test step, and spit out just the differences into a log file called that teststep. Sounded so easy :(

In other words, I need a groovy script that's going to sit at the end of the test case and run through all failed test steps inside that testcase then compares each line in the response to its corresponding line in the test step assertion contains(its called Contains Assertion which is literally a copy paste of a previous valid and working response) and then we need to spit out the line(s) that are different into a log/file. Here's what I have so far (rad, i fixed the previous error)

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

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

StepList.each
{
    if(it.metaClass.hasProperty(it,'assertionStatus'))
    {
        if(it.assertionStatus == AssertionStatus.FAILED)
        {
            def ass = it.getAssertableContentAsXml()
            def res = it.getTestStep().getPropertyValue('Response')
            log.error "Test Step: ${it.name} " + "${it.assertionStatus}"
            log.info ass 
            log.info res
        }
    }
}
1

There are 1 answers

0
imp On BEST ANSWER

RIGHT!! I GOT IT!! (ok except the compare bit but there are so many ways to do that depending on your goal). Thanks to everyone that helped with this :)

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

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
//Going through each step
StepList.each
{//check for property and declare it
    if(it.metaClass.hasProperty(it,'assertionStatus'))
    {//using it to check AssertionStatus
        if(it.assertionStatus == AssertionStatus.FAILED)
        {//ass=Assertion res=Response of step
            def ass = ""
            def assList = testRunner.getTestCase().getTestStepByName("${it.name}").getAssertionList()
            for(x in assList)
                {
                    ass = x.getToken().toString()
                }
            def res = it.getTestStep().getPropertyValue('Response').toString()
            log.error " Test Step: ${it.name} " + "${it.assertionStatus}"
            log.info "Response: "+res
            log.info "Assertion: "+ass
            //compare assertion to response and log differences

        }
    }
}
return;