[SoapUI] Compare TP and live environment of the XML Response, the code according to the function of the split, according to the directory of the code to automatically get the path of mapping files, automatically get the test step name

Source: Internet
Author: User
Tags soapui

Import Org.custommonkey.xmlunit.*import Org.custommonkey.xmlunit.examples.*import Javax.xml.xpath.*import Javax.xml.parsers.*import static java.lang.math.* import com.eviware.soapui.support.groovyutils//the parameter Allowabledeviation means the allowable deviation can be? percent, e.g Allowabledeviation = 0.03, the allowable deviation is 3%def allowabledeviation = 0.03def Maxrecordfail = 20 ArrayList failmessagelist = new ArrayList () String uidataname, Ticker, XPATHOFDIFFDATANAME, Failmessagedef Currentstepindex = context.currentstepindexstring Currentstepname = testRunner.testCase.getTestStepAt ( Currentstepindex). namestring previousstepname = testRunner.testCase.getTestStepAt (currentStepIndex-1). namestring Preprestepname = TestRunner.testCase.getTestStepAt (currentStepIndex-2). namestring Dataidmappingfile = TestRunner.testCase.testSuite.project.getPropertyValue ("Dataidmappingfile") String Testresultpath = TestRunner.testCase.testSuite.project.getPropertyValue ("Testresultpath") def Xmllive=context.expand (' ${' +preprestepname+ ' #Response} ') def xmltp=context.expand (' ${' +previousstepname+ ' # Response} ') def groovyutils = new Groovyutils (context) def xmlholderlive = Groovyutils.getxmlholder (xmllive) Diff Difftot Al= New Diff (xmllive, XMLTP) Detaileddiff Xmldetaileddiff = new Detaileddiff (difftotal) def difflist = Xmldetaileddiff.getalldifferences () int difflistsize=difflist.size () log.info "TP vs Live, different number in all:" +dif Flistsizeif (maxrecordfail>difflistsize| | maxrecordfail<=0) {maxrecordfail=difflistsize}if (difflistsize>0) {for (i = 0; i < difflistsize; i++) {Strin G Diff=difflist.get (i)//log.info "difference:" +diff if (Diff.contains ("holding")) {failmessage = "Holdi Ng is different, TP = "+diff.split (" Holding > ") [1].split (" < ") [0]+", "+" Live = "+diff.split (" Holding ' > ") [2].sp Lit ("<") [0] Failmessagelist.add (failmessage)} if (Diff.contains ("PA001")) {failmessage = "portfol Io Id is different , TP = "+diff.split (" ") [1]+", "+" Live = "+diff.split (" ' ") [3] Failmessagelist.add (failmessage)} Str ing diffdataid = diff.split ("@") [2].trim () string tpdatavalue = Diff.split ("'") [1] String livedatavalue =diff.split ( "'") [3] if ((tpdatavalue== "") && (livedatavalue!= "")) | | (tpdatavalue!= "") && (livedatavalue== "")) {Addfailmessageaboutdatavaluenull (Failmessagelist, Tpdatavalue,livedatavalue, diff, Diffdataid, xmlHolderLive, dat Aidmappingfile)} if (Tpdatavalue.isfloat () &&livedatavalue.isfloat ()) {Addfailmessageaboutdatavaluediff (    Failmessagelist, Tpdatavalue,livedatavalue, diff, Diffdataid, xmlholderlive, Dataidmappingfile, AllowableDeviation)} if (Failmessagelist.size () ==maxrecordfail) {Break} if ((i = = (diffListSize-1)) && (Failmessagelist.size () <maxrecordfail)) {maxrecordfail = Failmessagelist.size ()}}}if (maxrecordfail>0) {def testresultfile = new File (  testresultpath+ currentstepname+ ". txt")     if (testresultfile.exists ()) {Testresultfile.delete ()}for (j=0; j<maxrecordfail; J + +) {String Currentfailmessa GE = failmessagelist.get (j) log.error Currentfailmessage testresultfile.append (currentfailmessage+ "\ n")}assert false , Failmessagelist.get (0)}def getdatanameinmapping (String diffdataid,string dataidmappingfile) {def xmlDataIdMapping= New Xmlparser (). Parse (Dataidmappingfile) for (it in xmldataidmapping.f) {String Mapdataid = "${it.attribute (" I ") } "//log.info" Mapdataid = "+mapdataid if (mapdataid = = diffdataid) {uidataname =" ${it.attribut E ("Udlbl")} "return Uidataname}}} def gettickerbyxpath (String xpathofdiffdataname,object xmlhold erlive) {String ticker = Xmlholderlive.getnodevalue (XPATHOFDIFFDATANAME) return ticker} DEF getxpathofdataname (stri ng diff) {String diffdatavaluexpath = Diff.split ("at") [2] String Diffdatanamexpath = diffdatavaluexpath.split ("@") [ 0]+ "@OS385" return DiffdatAnamexpath}def Addfailmessageaboutdatavaluediff (ArrayList failmessagelist, String tpdatavalue, String livedatavalue, String diff, string diffdataid, Object xmlholderlive, String dataidmappingfile, float allowabledeviation) {float Tpdatava Luefloat = Tpdatavalue.tofloat () float livedatavaluefloat = livedatavalue.tofloat () Float benchmark = LIVEDATAVALUEFL Oat if (livedatavaluefloat ==0) {benchmark = tpdatavaluefloat} if (Math.Abs ((livedatavaluefloat-tpdatavaluefloat)/ Benchmark) >allowabledeviation) {//log.info "Diffdataid =" + Diffdataiduidataname = getdatanameinmapping (DiffDataID , dataidmappingfile) Xpathofdiffdataname = Getxpathofdataname (diff) Ticker =gettickerbyxpath (Xpathofdiffdataname , xmlholderlive) failmessage = "Data Value is different, TP =" +tpdatavalue+ ", Live =" +livedatavalue+ ", Ti Cker = "+ticker+", data point = "+uidataname+", Data ID = "+diffdataidfailmessagelist.add (failmessage)}}def addfailmess Ageaboutdatavaluenull (ArrayList FailmessagEList, String tpdatavalue, String Livedatavalue, String diff, string diffdataid, Object xmlholderlive, String Dataidmappi NgFile) {uidataname = getdatanameinmapping (diffdataid,dataidmappingfile) xpathofdiffdataname = getXPathOf Dataname (diff) Ticker =gettickerbyxpath (xpathofdiffdataname,xmlholderlive) failmessage = "Data Valu E is different, TP = "+tpdatavalue+", Live = "+livedatavalue+", Ticker = "+ticker+", Data point = "+uidataname+", Dat A ID = "+diffdataid failmessagelist.add (Failmessage)}

  

[SoapUI] Compare TP and live environment of the XML Response, the code according to the function of the split, according to the directory of the code to automatically get the path of mapping files, automatically get the test step name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.