0

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
        }
    }
}
imp
  • 435
  • 6
  • 20
  • I am using non pro version of SoapUI 5.1.3 – imp Jun 11 '15 at 12:36
  • This sounds like a very broad discussion - both of which are off-topic for SO. You will have to pick an approach that **you** feel comfortable with, then show us what you have and what is wrong. One thing I can suggest: think of the problem *outside* of SoapUI: how would you solve it in the abstract, what parts can SoapUI do for you, and else will you need. – SiKing Jun 11 '15 at 14:45
  • Not sure how to do this. Very new to SO and my apologies if this isn't the right place (this community is very helpful) I need a groovy script that's going to sit at the end of the test case and needs to run through all failed test step responses and compare line for line the response to that test step assertion type called contains. The contains is literally a copy paste of a previous valid and working response – imp Jun 11 '15 at 16:51
  • 1
    Use the edit button to enhance your original question. Do not put code in the comments. – SiKing Jun 11 '15 at 16:59
  • Thank you SiKing - I hope its better this time round – imp Jun 11 '15 at 17:23
  • OK - that should be the last edit for tonight, my time has run out :( – imp Jun 11 '15 at 19:20
  • @MistaWizard, the error posted by you show the problem clearly, you see that? It is used WsdlTestCase.testSteps(String) method with such signature is not present, so the error. It is suggesting to use getTestSteps() instead of testStesps(stepname). Try that out. – Rao Jun 12 '15 at 11:36
  • @Rao Yea I did attempt to change testSteps to getTestSteps using both [] and () to no avail. Also - regarding the other post on smartbear --> That way requires writing to a file, which can't happen on the server with limited space - these responses are going to be huge, and many – imp Jun 12 '15 at 11:53
  • My dear friend once you have the XMLs you need to look at this question http://stackoverflow.com/questions/141993/best-way-to-compare-2-xml-documents-in-java If you are able to get this to work you should build this into a custom step and publish. I have wanted to do exactly this for a while but haven't been able to get around to it. – Abhishek Asthana Jun 16 '15 at 12:54
  • My best result so far was with using that xmlUnit method, but it wasn't elegant nor was it robust enough as far as i could see. I've been using `StringUtils` from org.apache but this seems to be even less robust - not even working atm – imp Jun 16 '15 at 13:14
  • The implementation seems simple enough, what problems are you facing still? – Abhishek Asthana Jun 16 '15 at 16:18
  • The APIs dont seem robust enough to me, I'm not going to stop at just spitting out the differences. Theres going to be alot of different types of these checks. this link here is exactly what i need https://code.google.com/p/google-diff-match-patch/wiki/LineOrWordDiffs I'm busy learning eclipse so i can compile the java code – imp Jun 16 '15 at 17:57
  • I'm almost there! Now the line "getAssertableContentAsXml" is the issue, apparantly that gets the response, not the assertions :( – imp Jun 17 '15 at 11:13
  • 1
    Did you see this question about the value of the assertion? http://stackoverflow.com/questions/18613218/how-to-get-assertion-value-using-groovy-script – Abhishek Asthana Jun 17 '15 at 12:28

1 Answers1

0

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;
imp
  • 435
  • 6
  • 20