簡體   English   中英

執行Groovy腳本時拋出運行時異常

[英]Runtime exception thrown while executing groovy script

我是groovy腳本的新手,我的任務是比較從2個端點接收到的XML響應。 響應內容將保持不變,但標記,名稱空間前綴的順序可能有所不同。 我研究並提取了Groovy腳本語句,並按如下所示對腳本進行了框架設計。

import java.io.File`;
import java.util.Date;
import jxl.*;
import org.custommonkey.xmlunit.*
import groovy.xml.*
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def xml1 = new XmlSlurper().parseText( new File("D:\\GroovyTest\\responses\\getCustDetA.xml_Response.xml").getText())
def xml2 = new XmlSlurper().parseText( new File("D:\\GroovyTest\\responses\\getCustDetB.xml_Response.xml").getText() )
XMLUnit.setIgnoreWhitespace(true)
XMLUnit.setIgnoreComments(true)
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true)
XMLUnit.setNormalizeWhitespace(true)
def xmlDiff = new Diff(xml1,xml2)
assert xmldiff.identical()

當我運行腳本時,運行時會發生以下異常。 請幫助解決此問題或建議以更好的方式編寫它。

groovy.lang.GroovyRuntimeException: Could not find matching constructor
  for: org.custommonkey.xmlunit.Diff(groovy.util.slurpersupport.NodeChild,
  groovy.util.slurpersupport.NodeChild) error at line: 13

Diff不會將Groovy Slurper的NodeChild類用作構造函數參數(如異常中所述)

該類JavaDoc所示 ,您可以只使用Strings,即:

String xml1 = new File("D:\GroovyTest\responses\getCustDetA.xml_Response.xml").text
String xml2 = new File("D:\\GroovyTest\\responses\\getCustDetB.xml_Response.xml").text
def xmlDiff = new Diff(xml1,xml2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM