Forum Discussion
ShasiSingh
Occasional Contributor
Before running the below code download xmlunit jar file and Copy XMLUnit jar file under SOAPUI_HOME/bin/ext, then restart soapui.
The below code is written inside ( TestSuite-->TestCase-->Groovy Script -->)
Look for references here
import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.List; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.Difference; import org.xml.sax.SAXException; def String path01="C:\\SoapOutPut\\Base\\TEST_ReqV03_GetV02.xml"; def String path02="C:\\SoapOutPut\\Base\\TEST_ReqV04_GetV03.xml"; // Calling function to validate the outcome ComparisonTest (path01,path02) def ComparisonTest (filepathOrginal,filepathnew) { FileReader fr1 = null; FileReader fr2 = null; try { fr1 = new FileReader(filepathOrginal); fr2 = new FileReader(filepathnew); } catch (FileNotFoundException e) { e.printStackTrace(); } try { Diff diff = new Diff(fr1, fr2); log.info ("Similar record is --> " + diff.similar()); log.info ("Identical record is --> " + diff.identical()); DetailedDiff detDiff = new DetailedDiff(diff); List differences = detDiff.getAllDifferences(); for (Object object : differences) { Difference difference = (Difference)object; log.info ("***********************"); log.info(difference); log.info("***********************"); } } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
radhika1
6 years agoContributor
Hi,
Thanks for the code but i need to compare two json responses.the code that you have given is for xml.
Related Content
Recent Discussions
- 45 minutes agoKLWallace
- 7 days agoruchisingh