[SoapUI] 比较TP和Live环境下的XML Response,将代码按照功能进行拆分,根据代码所在目录自动获取Mapping文件所在路径,自动获取测试步骤名称

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.03
def maxRecordFail = 20
ArrayList failMessageList = new ArrayList()
String UIDataName, ticker, XPathOfDiffDataName, failMessage

def currentStepIndex = context.currentStepIndex
String currentStepName = testRunner.testCase.getTestStepAt(currentStepIndex).name
String previousStepName = testRunner.testCase.getTestStepAt(currentStepIndex-1).name
String prePreStepName = testRunner.testCase.getTestStepAt(currentStepIndex-2).name

String 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: "+diffListSize

if(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 =" + diffDataID
		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)
	 }
}

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)
}

  

时间: 2024-11-02 18:04:16

[SoapUI] 比较TP和Live环境下的XML Response,将代码按照功能进行拆分,根据代码所在目录自动获取Mapping文件所在路径,自动获取测试步骤名称的相关文章

[SoapUI] 比较两个不同环境下的XML Response, 从外部文件读取允许的偏差值,输出结果到Excel

import static java.lang.Math.* import java.text.NumberFormat import com.eviware.soapui.support.GroovyUtils import com.eviware.soapui.support.XmlHolder import org.apache.poi.ss.usermodel.Cell import org.apache.poi.ss.usermodel.Row import org.apache.po

[SoapUI] 比较API在两个测试环境下的XML response文件,找出不同的DataID和DataValue,并从另外一个保存着API DataID与UI DataName 映射关系的XML文件中读取DataName

import org.custommonkey.xmlunit.* import javax.xml.xpath.* import javax.xml.parsers.DocumentBuilderFactory import javax.xml.parsers.*; String UIDataName = "" def responseTP= new FileReader( new File('D:\\Study\\MA\\xml_TP.xml')) def responseLive

Web环境下applicationContext.xml文件配置

在web环境下(web.xml)如何配置applicationContext.xml文件 <listener>  <listener-class>   org.springframework.web.context.ContextLoaderListener  </listener-class> </listener> 或: <servlet>  <servlet-name>context</servlet-name>  

[SoapUI] 比较TP和Live环境中API的XML response,打印多条不同的地方,比较数据时允许偏差值,同时错误信息中数据点ID通过映射表替换成UI上数据点的名字

import org.custommonkey.xmlunit.* import javax.xml.xpath.* import javax.xml.parsers.DocumentBuilderFactory import javax.xml.parsers.* import static java.lang.Math.* String xmlTP = "D:\\Study\\MA\\xml_TP.xml" String xmlLive = "D:\\Study\\MA\

[SoapUI] 比较两个不同环境下的Response, 结果不同时设置Test Step的执行状态为失败

import org.custommonkey.xmlunit.* def responseTP=context.expand( '${Intraday Table_TP#Response}' ) def responseLive=context.expand( '${Intraday Table_Live#Response}' ) if (responseTP == responseLive) { log.info "Test case pass" assert true } els

cocos2dx3.0-tinyxml在Android环境下解析xml失败的问题

正常情况下,我们在用tinyxml读取xml文件的的时候,会像下面这样写. 1 std::string filePath = FileUtils::getInstance()->getWritablePath() + fileName;//获取文件路径. 2 XMLDocument *pDoc = new XMLDocument();//创建一个空的XMLDocument 3 XMLError errorId = pDoc->LoadFile(filePath.c_str());//用XMLD

在vSphere环境下简单测试Windows 2016 S2D (2)

在了解了S2D基本概念及架构以后,我们接下来做一些具体的配置及测试.本实验环境搭在vCenter6.0u2上,配置四台虚机作为S2D的节点,每台虚机的具体配置如下: OS:Windows 2016 datacenter 4 vCPU& 8GB RAM 4 vNics 1个40GB磁盘装OS:另外再添加2 x 50GB(模拟PCIe SSD):2 x 100GB(模拟SSD):4 x 300GB(HDD) 本测试的设想是将模拟的NVMe PCIe SSD磁盘作为读写缓存使用,而把SSD和HDD作为

由一个简单需求到Linux环境下的syslog、unix domain socket

本文记录了因为一个简单的日志需求,继而对linux环境下syslog.rsyslog.unix domain socket的学习.本文关注使用层面,并不涉及rsyslog的实现原理,感兴趣的读者可以参考rsyslog官网.另外,本文实验的环境实在debian8,如果是其他linux发行版本或者debian的其他版本,可能会稍微有些差异. 需求: 工作中有一个在Linux(debian8)环境下运行的服务器程序,用python语言实现,代码中有不同优先级的日志需要记录,开发的时候都是使用pytho

最新 Cocos2d-x 3.2 开发环境搭建(windows环境下)

本篇是基于Cocos2d-x-3.2和vs2012的环境下配置. 1.先从官方站点(www.cocos2d-x.org)下载 Cocos2d-x-3.2文件. 2.因为Cocos2d-x 3.0以上的版本号要求系统windows7以上,vs2012以上.网上寻找并下载VS2012的镜像以及密钥,安装好vs2012. 3.打开Cocos2d-x-3.2文件里的build文件里找到 "cocos2d-win32.vc2012.sln",然后双击执行. 4.在vs2012界面将"c