Forum Discussion
Hi Team,
Could you please let me know the solution for the same.
You can save the response and store it externally using code:
def ResFile ="C:/Response1.xml"
def Res = context.expand( '${TestStep#Response}' )
def j = new File(ResFile)
j.write(Res, "UTF-8")
You can use the Groovy XMLUnit utility like this to compare the XML files.
XMLUnit.setIgnoreWhitespace(true)
XMLUnit.setIgnoreComments(true)
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true)
XMLUnit.setNormalizeWhitespace(true)
XMLUnit.compareXML(expectedXml, actualXml)
- radhika16 years agoContributor
hello,
Could you please give me the script to compare two json files and print the mismatches in tags and values please...Any help is highly appreciated.
- ShasiSingh6 years agoOccasional 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(); } }
- radhika16 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
- 24 hours agoGuhan-B
- 5 days agoruchisingh