标签:
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
最终执行结果:
标签:
原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4621116.html