Forum Discussion

AAB's avatar
Regular Contributor
6 years ago

How to compare 2 responses from 2 different testcases?

Hi all,


I'm a bit in a deadlock here. 


Is there anyone who could give me an idea on how I best compare 2 responses (in different extensions) from 2 different testcases please?


I've tried the following:

TestCase1: DataSource1 (to get the information from an external source)

                   Property Transfer1

                   SOAP request (send the property to find the item - Response is Xml)

                   Property Transfer (to DataSink)

                   DataSink1 (I've tried excel to stash the answer but for the next testcase I will have problems, so actually not a very good idea)

                   DataSource Loop


TestCase2: DataSource2 (to get the information from our internal DB)

                   Property Transfer2

                   RESTrequest (GET - send the property to find the item - response is json)

                   Property Transfer (to DataSink)

                   DataSink2 (also trying to stash that in excel, but I don't know how to parse json in excel, and explicitly the parameters that I want)

                   DataSource Loop


There is no possibility to put those 2 requests in the same testcase as they both use different VPN's. Our architect will change that in do time, but for now, I need to be able to execute it in 2 different testcases.


Does anybody has an idea on what would be the most suitable approach for this comparision please? Because I'm stuck.

Thanks in advance.


  • AAB's avatar
    6 years ago

    Hi everyone,


    For those who are wondering how I solved this: our senior developer has proposed to do it with a GroovyScript. This is, apparently, not a possibility yet to do it with the ReadyAPI point and click in the project I'm working on. Wondering if this could be implemented at all.....? But here we go.

    Read the question again to set up the testcases.

    After this, add a third Testcase with only a Groovy Step.

    Add this code:


    File kboFile = new File('CompletePathToYourFile/ResultsKBO.txt')
    File pdcFile = new File('CompletePathToYourFile/ResultsPDC.txt')
    if (kboFile.exists() && kboFile.canRead() && pdcFile.exists() && pdcFile.canRead()) {
        println "Both files exist!"
    	File outputFile = new File('CompletePathToYourFile/output.html')
        outputFile.write "<html><head><style>h{color:#86BEB6; font-size:50px;}</style><title>Comparison Results PDC</title></head><body><img src='AnImagethatyouwanttoAdd'  alt='ThenameofanImagethatyouwanttoAdd' ><br /><h>Test results comparison KBO with PDC</h><div style = 'border: 1px solid black; border-collapse: collapse;'><p>Automated tests are executed in ReadyAPI. These are the results of the comparison on the responses between KBO and PDC</p></div>"
    	outputFile.append "<table style='margin-top:10px; width:50%'><tr><th>CBE_Number</th><th>Information</th><th>Difference</th></tr>"
        kboFile.newReader().eachLine { currentKboFileLine ->
            def currentKboFileLineItems = currentKboFileLine.split(",")
            String cbeNumber = "Unknown by KBO"
            if(currentKboFileLineItems.length > 0) {
             cbeNumber = currentKboFileLineItems[0] //look for cbenumber
    	   // ( cbeNumber) //print in commandline
    	   // ( cbeNumber.trim().isEmpty()) //this will check if he recognizes whitespaces
            StringWriter writer = new StringWriter()
            pdcFile.filterLine(writer) { line ->
            def color = "green" //default color is green
            if (writer.toString().isAllWhitespace()) {   //if the string is empty
    		color = "red"
    		//outputFile.append "<p style='color: "+color+"'><span style='font-weight: bold'>CBE: " + cbeNumber + "</span> - "
    		outputFile.append"<tr  style='color: "+color+"'><td align='center'>" + cbeNumber + "</td><td align='center'>"
                for(int i=1;i<currentKboFileLineItems.length;i++) {
                	outputFile.append currentKboFileLineItems[i]
                	if( i< currentKboFileLineItems.length-1 ) {
                		outputFile.append ","
                outputFile.append "</td></tr>"
        outputFile.append "</table></body></html>"
    } else {"One of the files doesn't exist!")

    "CompletePathToYourFile" is what this concatenation says, so you start from your "C:". Don't forget that if you copy past the path from your explorer it will give you backslashes and Groovy is allergic to that, so you need to change this in front slashes ( " / " ).




    <img src='AnImagethatyouwanttoAdd' alt='ThenameofanImagethatyouwanttoAdd' >


    I've inserted an image to encounter my clients property. You can leave this one out if you want to.


    So here HTML has been incubated in the code so you'll have an html overview of the results.

    Don't forget to create the necessary files on your harddrive for the test. In this case you'll need a 

    • GoldenKBO.xml file
    • GoldenPDC.xml file
    • Output.xml file

    Possible results:

    You can expand the HTML as you wish.

    I'm still elaborating to show the differences IN the string, but for that I need to have a look arround or ask someone.


    Have fun and nice testing!  :-)  






10 Replies

  • nmrao's avatar
    Champion Level 3
    Thumb rule : Each and every test case should be independent and they should be runnable without any dependency on other tests.

    If this is not the case, need to reconsider the test case design.
    • AAB's avatar
      Regular Contributor

      Hey there nmrao ,


      Yes you are right, and that's the case here. Each of the testcases are runnable and give their own responses. Except that the responses of both testcases should be compared to verify that both environments have the same data.


      Kind regards,


      • nmrao's avatar
        Champion Level 3
        Still I don't buy that a proper independent test.

        Any ways, comparison of xml can be done in multiple ways. But depends on the data, can't be simple generic solution.