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.
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 ( " / " ).
<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! :-)
Cheers,
AboveAndBeyond