compare with two XML

本文介绍了一种使用Groovy脚本对比两个XML响应文件的方法。通过提取XML中的表头和数据单元格内容,逐项比较验证数据的一致性,并记录比对结果。对于比对成功的数据点,将加入到列表中;若数据点比对失败,则记录详细信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def responseDB =groovyUtils.getXmlHolder("WeightingCheck#ResponseAsXml")
def xmlUtil = new com.eviware.soapui.support.xml.XmlUtils();
def DBnodes = responseDB.getDomNodes( "//*" );
for( node in DBnodes ){
    def DBvalue = com.eviware.soapui.support.xml.XmlUtils.getNodeValue( node )

    log.info node.getNodeName()
    log.info DBvalue
    }

//import com.eviware.soapui.support.xmlHolder

 

//import groovy.util.XmlParser

def response3X = context.expand('${Get3XList#response}')

def responseCloud = context.expand('${GetCloudList#response}')

def ArrayList list  = new ArrayList();

//assert response3X.contains(responseCloud)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def request3X = groovyUtils.getXmlHolder(response3X)

 

def requestCloud = groovyUtils.getXmlHolder(responseCloud)

 

//get Node Values

def ths3X = request3X.getNodeValues("//thead/tr/th")
def thsCloud = requestCloud.getNodeValues('//thead/tr/th')
def tds3X = request3X.getNodeValues("//tbody/tr/td")
def tdsCloud = requestCloud.getNodeValues('//tbody/tr/td')
def count1s = thsCloud.size()

def count2s = tdsCloud.size()

//Compare with each other

for (i=0;i<count1s;i++){
if (thsCloud[i]==ths3X[i])
log.info "data convent data point successfully"
else
log.info " the Cloud is" + thsCloud[i]  +"   ths3X is" + ths3X[i]

}

for(def j=1; j<count2s;j++){  //check the value of the data points
    if (tdsCloud[j]==tds3X[j]){
    //log.info '"' + ths3X[j%count1s]+'"'+ " data value convent successfully"
    list.add(ths3X[j%count1s])  //add the successfully data points to the list
     }
    else{
      log.info "data value convent Failed, the 3x data point is: " + ths3X[j%count1s]
      //log.info "3X is: " + tds3X[j] +"   cloud is: "+ tdsCloud[j]
   // list.add(ths3X[j%count1s]) //add the failed data points to the list
     
  }

  HashSet h =new HashSet(list)  / / remove the duplicate data points form the list
  list.clear()
  list.addAll(h)  
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值