Forum Discussion
But in this context, it is not clear what to compare. Or missing something?
The sample data which I have provided , I'm reading it from excel and I'm comparing it with the soap response from soapUI which I get when I run a test step
- nmrao5 years agoChampion Level 3Unable to use the given information to try out a solution.
- PrathapR5 years agoFrequent Contributor
Currently I'm also working on same task. I'm using XMLUnit2 to compare two soap responses.
The only diffrenece from your case, I'm comaring two resaponses from external files(C://SoapUI//response1 etc..).
I would suggest to use XMLUnit2, we can ignore some attributes/node upon our requirement.
Please refer some post which I did,
lety me know, if you have any questions.
- roja15 years agoContributor
PrathapR ,
Sorry for the late response. I have tried the way you suggested. And I'm getting org.xmlunit.XMLUnitException:Content is not allowed in prolog.
Please find the below code:
import static java.nio.charset.StandardCharsets.*;
import java.lang.*;
import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
import com.eviware.soapui.support.XmlHolder
import jxl.*
import jxl.write.*
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode
import groovy.json.JsonSlurper
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.diff.Diff
def count=0,i=1,j=1,k=1
def inputFileName,outputFileName
def inputFile = testRunner.testCase.testSuite.getPropertyValue("inputFileName")
def outputFile = testRunner.testCase.testSuite.getPropertyValue("outputFileName")
def testStep = testRunner.testCase.testSteps["Properties"]Workbook inputWB = Workbook.getWorkbook(new File(inputFile))
Sheet inputSheet = inputWB.getSheet(0)
no_of_rows= inputSheet.getRows().toInteger()Workbook existingInputWB=Workbook.getWorkbook(new File(inputFile))
WritableWorkbook outputWB=Workbook.createWorkbook(new File(outputFile),existingInputWB)testCaseName=testRunner.testCase.name
outputWB.createSheet(testCaseName,2)
WritableSheet sheet_writable = outputWB.getSheet(testCaseName)
(0..context.testCase.testStepCount-1).each{
def step1 = context.testCase.testStepList[it]
if ( step1 instanceof WsdlTestRequestStep) {
for(j=1;j<no_of_rows;j++){
Cell f=inputSheet.getCell(0,j)
if(f.getContents()!='')
{
step_name=f.getContents()
Cell f1=inputSheet.getCell(3,j)
def String step_response=f1.getContents()
step_response=new XmlSlurper().parseText(step_response)
def String response = context.expand(step1.getPropertyValue('Response'))
//response=response.replaceAll(" ","")
if(step1.name==step_name&&step1.name!=null){
Diff mydiff=DiffBuilder.compare(response).withTest(step_response).ignoreComments().ignoreWhitespace().checkForSimilar().build()
log.info (mydiff.toString())
}
}
}
}
}
outputWB.write()
outputWB.close()
existingInputWB.close() - roja15 years agoContributor
I got to know that this kind of error occurs when something is present before <?xml . But my response doesn't have <?xml at all. How can I get rid of this error and compare my responses?
- PrathapR5 years agoFrequent Contributor
Did a sample, stored 1 xml in Excel cell, as like your snapshot, once see below code, It worked for me.
import com.eviware.soapui.support.XmlHolder
import jxl.*
import jxl.write.*
import com.eviware.soapui.support.*;
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.diff.Diff
import org.xmlunit.diff.*
def counter,next,previous,size
Workbook workbook1 = Workbook.getWorkbook(new File("C:\\SOAP\\Book1.xls"))
Sheet sheet1 = workbook1.getSheet(0)size= sheet1.getRows().toInteger()
//Intially set count 0 or 1 (Deepends on rows in excel) at test case
counter1 = context.testCase.getPropertyValue("Count").toString()
counter = counter1.toInteger()
def response = testRunner.testCase.getTestStepByName("getSoapTestStep").getPropertyValue("response");
next = (counter > size-2? 1: counter+1)
Cell c1 = sheet1.getCell(3,counter)
baseXML= c1.getContents()context.testCase.setPropertyValue("Count", next.toString()) ;
def Count = context.testCase.getPropertyValue("Count") ;
Diff mydiff=DiffBuilder.compare(response).withTest(baseXML).ignoreComments().ignoreWhitespace().checkForSimilar().build()
for (Difference d : mydiff.getDifferences()) {
log.error d
}
next++ //increase next valueworkbook1.close()
Related Content
- 9 months agoLuukdb
Recent Discussions
- 15 hours agoruchisingh