[SoapUI] 比較TP和Live環境下的XML Response,將代碼按照功能進行拆分,根據代碼所在目錄自動擷取Mapping檔案所在路徑,自動擷取測試步驟名稱

來源:互聯網
上載者:User

標籤:

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 = 20ArrayList 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 diffTotal= 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: "+diffListSizeif(maxRecordFail>diffListSize||maxRecordFail<=0){    maxRecordFail=diffListSize}if(diffListSize>0){for (i = 0; i < diffListSize; i++) {    String diff=diffList.get(i)//    log.info " Difference  : "+diff     if(diff.contains("holding")){        failMessage = " Holding is different , TP = "+diff.split("holding‘>")[1].split("<")[0]+"  , "+ "Live = "+diff.split("holding‘>")[2].split("<")[0]        failMessageList.add(failMessage)    }     if(diff.contains("PA001")){        failMessage = " Portfolio Id is different , TP = "+diff.split("‘")[1]+"  , "+ "Live = "+diff.split("‘")[3]        failMessageList.add(failMessage)    }         String 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, dataIdMappingFile)    }  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 currentFailMessage = 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.attribute("udlbl")}"             return UIDataName          }    }} def getTickerByXPath(String XPathOfDiffDataName,Object xmlHolderLive){    String ticker =  xmlHolderLive.getNodeValue(XPathOfDiffDataName)    return ticker} def getXPathOfDataName(String 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 TPDataValueFloat = TPDataValue.toFloat()      Float LiveDataValueFloat = LiveDataValue.toFloat() Float benchmark = LiveDataValueFloat 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+" , Ticker = "+ticker+" , Data Point = "+UIDataName+" , Data ID = "+diffDataIDfailMessageList.add(failMessage) }}def addFailMessageAboutDataValueNull(ArrayList failMessageList, String TPDataValue, String LiveDataValue, String diff, String diffDataID, Object xmlHolderLive,  String dataIdMappingFile){  UIDataName = getDataNameInMapping(diffDataID,dataIdMappingFile)                 XPathOfDiffDataName = getXPathOfDataName(diff)        ticker =getTickerByXPath(XPathOfDiffDataName,xmlHolderLive)                failMessage = " Data Value is different , TP = "+TPDataValue+" , Live = "+LiveDataValue+" , Ticker = "+ticker+" , Data Point = "+UIDataName+" , Data ID = "+diffDataID       failMessageList.add(failMessage)}

  

[SoapUI] 比較TP和Live環境下的XML Response,將代碼按照功能進行拆分,根據代碼所在目錄自動擷取Mapping檔案所在路徑,自動擷取測試步驟名稱

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.