cancel
Showing results for 
Search instead for 
Did you mean: 

How to compare 2 responses from 2 different testcases?

SOLVED
Contributor

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.

Cheers.

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: How to compare 2 responses from 2 different testcases?

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(",")
        
        log.info(currentKboFileLineItems.length)
        String cbeNumber = "Unknown by KBO"
        if(currentKboFileLineItems.length > 0) {
         cbeNumber = currentKboFileLineItems[0] //look for cbenumber
        }
	   
	   //log.info ( cbeNumber) //print in commandline
	   //log.info ( cbeNumber.trim().isEmpty()) //this will check if he recognizes whitespaces
	   
        StringWriter writer = new StringWriter()
        pdcFile.filterLine(writer) { line ->
            line.startsWith(cbeNumber)
        }

        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 {
    log.info("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 ( " / " ).

 

backslashes.png

 

 

<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:

results.png

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

 

Cheers,

AboveAndBeyond

 

 

10 REPLIES 10
Community Hero

Re: How to compare 2 responses from 2 different testcases?

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.


Regards,
Rao.
Contributor

Re: How to compare 2 responses from 2 different testcases?

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,

AboveAndBeyond.

Community Hero

Re: How to compare 2 responses from 2 different testcases?

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.


Regards,
Rao.
Moderator

Re: How to compare 2 responses from 2 different testcases?

Please check this thread which can be helpful for you: https://community.smartbear.com/t5/SoapUI-Pro/Compare-response-to-table-values/m-p/116038?advanced=f...Smiley Frustrated


Anastasia
Customer Care Team


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

Contributor

Re: How to compare 2 responses from 2 different testcases?

Thanks @Nastya_Khovrina   but it doesn't help. These are things that I've already tried out but as I'm not known with groovy I can't change the code for my purpose.

Also, I was kind of hoping that ReadyAPI would have been strong enough to do it "automaticaly" like all the other great stuff that are in it like 'point and click'. I have created the concept with a

  • Groovy script
  • datasource
  • property transfer
  • rest request/soap request
  • datasource loop
  • datasink

but I'm still stuck on the comparison.

Contributor

Re: How to compare 2 responses from 2 different testcases?

EXTRA:

I've found out how to parse Json in excel. Actually, I needed to put the response from the 'Property Transfer to DataSink' in language "JSONPath" for all my properties. Apparently that did the work. So I could compare the response in excel, but in do time excel will have his limits as the total of responses will grow dynamically so in the futur not usable..... :-(

I will sit down with our senior developper today. Maybe he find something.

 

 

Community Manager

Re: How to compare 2 responses from 2 different testcases?

Hi @AboveAndBeyond,

Please let us know if you find a more convenient way to implement your task.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: How to compare 2 responses from 2 different testcases?

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(",")
        
        log.info(currentKboFileLineItems.length)
        String cbeNumber = "Unknown by KBO"
        if(currentKboFileLineItems.length > 0) {
         cbeNumber = currentKboFileLineItems[0] //look for cbenumber
        }
	   
	   //log.info ( cbeNumber) //print in commandline
	   //log.info ( cbeNumber.trim().isEmpty()) //this will check if he recognizes whitespaces
	   
        StringWriter writer = new StringWriter()
        pdcFile.filterLine(writer) { line ->
            line.startsWith(cbeNumber)
        }

        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 {
    log.info("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 ( " / " ).

 

backslashes.png

 

 

<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:

results.png

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

 

Cheers,

AboveAndBeyond

 

 

Community Manager

Re: How to compare 2 responses from 2 different testcases?

Thanks for sharing the solution with us!

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2