cancel
Showing results for 
Search instead for 
Did you mean: 

compare expected output read from excel with the soapUI response

Highlighted
Contributor

compare expected output read from excel with the soapUI response

Hi,

 

I'm reading expected output from excel and comparing it with the actual response from soapUI. Even though both of the values are matcing comparision is failing. Please help me with this. Appreciate your help in advance.

Below is the code I have used :

import static java.nio.charset.StandardCharsets.*;
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.testSuite
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 inputWB = Workbook.getWorkbook(new File(inputFileName))
Sheet inputSheet = inputWB.getSheet(0)
no_of_rows= inputSheet.getRows().toInteger()

Workbook existingInputWB=Workbook.getWorkbook(new File(inputFileName))
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)
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
}
}

(0..context.testCase.testStepCount-1).each{
def step1 = context.testCase.testStepList[it]
if ( step1 instanceof RestTestRequestStep) {
Cell f=inputSheet.getCell(0,j)
step_name=f.getContents()
log.info step_name
log.info step1.name
Cell f1=inputSheet.getCell(3,j)
def String step_response=f1.getContents()
step_response=step_response.replaceAll(" ","")
//String step_response_utf = new String(step_response, "UTF-8");
log.info "from excel "+step_response
def String response = context.expand(step1.getPropertyValue('Response'))
response=response.replaceAll(" ","")
//String response_utf = new String(response, "UTF-8");
log.info "from soapui"+response
if(step1.name==step_name){
if(step_response==response)
{
log.info "Passed"
jxl.write.Label status = new jxl.write.Label(1,j ,"Passed")
sheet_writable.addCell(status)
}
else
{
log.info "Failed"
jxl.write.Label status = new jxl.write.Label(1,j ,"Failed")
sheet_writable.addCell(status)
}
}
j=j+1
}
}
outputWB.write()
outputWB.close()
existingInputWB.close()

2 REPLIES 2
Highlighted
Super Contributor

Re: compare expected output read from excel with the soapUI response

What is the error you are getting? And please mention the line number also.

Highlighted
Contributor

Re: compare expected output read from excel with the soapUI response

Hi, 

 

I'm not getting any error , but for the case when the comparision should pass also it printing failed. When I uncomment the lines I get the below error:

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.lang.String(java.lang.String, java.lang.String) error at line: 63