Compare expected output read from excel with soapui response
Hi,
I'm reading expected output from an excel file and comparing that value with response obtained in soapUI. Even though both the values are same I'm getting response as failed. Please help me with this. Appreciate your help in advance.
Below is the code that I have used:
import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
import com.eviware.soapui.support.XmlHolder
import jxl.*
import jxl.write.*
def count=0,i=1,j=1
def inputFileName,outputFileName
def testStep = testRunner.testCase.testSteps["Properties"]
if (testStep.getPropertyCount() > 0){
for (prop in testStep.getPropertyList()){
if(prop.getName()=="inputFileName"){
inputFileName=prop.getValue()
}
else if(prop.getName()=="outputFileName"){
outputFileName=prop.getValue()
}
}
}
Workbook existingInputWB=Workbook.getWorkbook(new File(outputFileName))
WritableWorkbook outputWB=Workbook.createWorkbook(new File(outputFileName),existingInputWB)
testCaseName=testRunner.testCase.name
outputWB.createSheet(testCaseName,2)
WritableSheet sheet_writable = outputWB.getSheet(testCaseName)
jxl.write.Label testStepCell = new jxl.write.Label(0,0 ,"Test Step")
jxl.write.Label reqUrlCell = new jxl.write.Label(2,0 ,"Request URL")
jxl.write.Label reqPayloadCell = new jxl.write.Label(3,0 ,"Request Payload")
jxl.write.Label responseCell = new jxl.write.Label(4,0 ,"Response")
jxl.write.Label statusCell = new jxl.write.Label(1,0 ,"Status")
jxl.write.Label reasonCell = new jxl.write.Label(5,0 ,"Reason")
sheet_writable.addCell(testStepCell)
sheet_writable.addCell(reqUrlCell)
sheet_writable.addCell(reqPayloadCell)
sheet_writable.addCell(responseCell)
sheet_writable.addCell(statusCell)
sheet_writable.addCell(reasonCell)
(0..context.testCase.testStepCount-1).each{
def step = context.testCase.testStepList[it]
if ( step instanceof RestTestRequestStep) {
jxl.write.Label stepName = new jxl.write.Label(0,i ,step.name)
sheet_writable.addCell(stepName)
def tr=testRunner.testCase.getTestStepByName(step.name)
def String endPointUrl= tr.getHttpRequest().getResponse().getURL()
jxl.write.Label reqUrl = new jxl.write.Label(2,i ,endPointUrl)
sheet_writable.addCell(reqUrl)
def payload = context.expand(step.getPropertyValue('Request'))
jxl.write.Label reqPayload = new jxl.write.Label(3,i ,payload)
sheet_writable.addCell(reqPayload)
def response = context.expand(step.getPropertyValue('Response'))
jxl.write.Label reqResponse = new jxl.write.Label(4,i ,response)
sheet_writable.addCell(reqResponse)
count=count+1
i=i+1
}
}
def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each{
if(it.metaClass.hasProperty(it,'assertionStatus')){
if(it.assertionStatus == AssertionStatus.FAILED){
jxl.write.Label anotherWritableCell10 = new jxl.write.Label(1,j ,"Failed")
sheet_writable.addCell(anotherWritableCell10)
}else if(it.assertionStatus == AssertionStatus.VALID){
jxl.write.Label anotherWritableCell10 = new jxl.write.Label(1,j ,"Passed")
sheet_writable.addCell(anotherWritableCell10)
}else if(it.assertionStatus == AssertionStatus.UNKNOWN){
jxl.write.Label anotherWritableCell10 = new jxl.write.Label(1,j ,"UNKNOWN (PROBABLY NOT ALREADY EXECUTED)")
sheet_writable.addCell(anotherWritableCell10)
}
j=j+1
}
}
outputWB.write()
outputWB.close()
existingInputWB.close()