码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-07-04 19:41:13      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

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= new FileReader(new File(‘D:\\Study\\MA\\xml_Live.xml‘))

def xmlDiff = new Diff(responseTP, responseLive)
boolean isSame = xmlDiff.similar();
log.info " Is TP and Live the same : "+isSame
String diff = xmlDiff.toString()
//log.info " Difference  : "+diff

String diffDataID = diff.split("@")[2].trim()
String TPDataValue = diff.split("‘")[1]
String LiveDataValue =diff.split("‘")[3]

//log.info "diffDataID =" + diffDataID

def xmlDataIdMapping= new XmlParser().parse(‘D:\\Study\\MA\\DataIdMapping\\DataIdMappingPA.xml‘)

for(it in xmlDataIdMapping.f){
	String mapDataID =  "${it.attribute("i")}"
     // log.info "mapDataID ="+mapDataID
      if(mapDataID == diffDataID){
      	 UIDataName =  "${it.attribute("udlbl")}"
      	 break
      }
} 

String diffDataValueXPath = diff.split("at ")[2]
//log.info "The XPath of the data value is : "+diffDataValueXPath
String diffDataNameXPath = diffDataValueXPath.split("@")[0]+"@OS385"
//log.info "The XPath of the data name is : "+diffDataNameXPath

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(new FileInputStream(new File("D:\\Study\\MA\\xml_TP.xml")));
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
String OS385 =  xpath.evaluate(diffDataNameXPath,  doc, XPathConstants.NODE).getValue();


String holding = OS385.split(">")[2].split("<")[0]

String failMessage= " Fail : Holding = "+holding+", Data Point = "+UIDataName+" , TP = "+TPDataValue+" , "+ "Live = "+LiveDataValue+" , Data ID = "+diffDataID
log.info failMessage
assert isSame,failMessage

最终执行结果:
技术分享

 

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

标签:

原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4621116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!