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 ...
  • 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!  :-)