I had this issue and this is what I could figure out to do.
import groovy.json.JsonSlurper
import java.text.SimpleDateFormat
import org.apache.commons.lang.StringUtils
filePath = context.testCase.testSuite.getPropertyValue("failedLog").toString()
f = new File(filePath)
def account = context.testCase.getPropertyValue("account")
def response1 = testRunner.testCase.getTestStepByName("Request1").getPropertyValue("response")
def slurperResponse1 = new JsonSlurper().parseText(response1)
def response2 = testRunner.testCase.getTestStepByName("Request2").getPropertyValue("response")
def slurperResponse2 = new JsonSlurper().parseText(response2)
def account = context.testCase.getPropertyValue("account")
status_code_1 = (slurperResponse1.status.code)
account_status_code_2 = (slurperResponse2.status.code)
if (status_code_1 <=> status_code_2) {
f.append '\n' + ("Account number " + account +" at " + "status_code" + " failed")
}
You would then have to map each line to pull the data from both requests, compare and apply some logic to report issues. This is fine if you have only a few fields to validate but if your response has 100 or more lines you might want to do something like this.
Have a step that writes the Raw Response into individual xml files then have a nother that will read each file line by line while comparing the lines.
Step 1
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def account = testRunner.testCase.getPropertyValue( "account" ) // pull account number to add text to the name of the file if running data driven test
def response1 = context.expand( '${Account - Request 1#RawResponse}' )
def response2 = context.expand( '${Account - Request 2#RawResponse}' )
//assert response == response2
//write payload to file
FP = filePath=projectPath+"\\Responses\\" + account + "_" + "response1.xml"
f = new File(FP)
f.append(response1)
//write payload to file
FP = filePath=projectPath+"\\Responses\\" + account + "_" + "response2.xml"
f = new File(FP)
f.append(response2)
Step 2
import java.io.FileReader;
import java.io.LineNumberReader;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def account = testRunner.testCase.getPropertyValue( "account" )
LineNumberReader r1 = new LineNumberReader(new FileReader(projectPath + "\\Responses\\" + account + "_" + "response1.xml"));
LineNumberReader r2 = new LineNumberReader(new FileReader(projectPath + "\\Responses\\" + account + "_" + "response2.xml"));
String line1 = null;
String line2 = null;
while ((line1 = r1.readLine()) != null) {
line2 = r2.readLine()
if (line1 != line2){
//log.info line1 + " - " + line2
FP = filePath=projectPath+"\\Discrepancies\\" + account + "_" + "discrepancy.txt"
f = new File(FP)
f.append(line1 + " <===> " + line2)
f.append '\n'
}
}
r1.close();
r2.close();