Groovy SoapUI log.info在比较两个xml文件并记录差异时会出于某种原因打开对话框

Groovy SoapUI log.info在比较两个xml文件并记录差异时会出于某种原因打开对话框,groovy,soapui,xmlunit,Groovy,Soapui,Xmlunit,由于某些原因,执行以下脚本时,不仅会在日志中打印输出,还会在信息弹出对话框中打印输出。有人能给我解释一下为什么会发生这种情况,以及我如何防止这种情况发生吗 import groovy.io.FileType; import org.custommonkey.xmlunit.*; def file1 = "somepath/file1.xml" def file2 = "somepath/file2.xml" def xml1 = new FileReader(file1) def xml2=

由于某些原因,执行以下脚本时,不仅会在日志中打印输出,还会在信息弹出对话框中打印输出。有人能给我解释一下为什么会发生这种情况,以及我如何防止这种情况发生吗

import groovy.io.FileType;
import org.custommonkey.xmlunit.*;

def file1 = "somepath/file1.xml"
def file2 = "somepath/file2.xml"

def xml1 = new FileReader(file1)
def xml2= new FileReader(file2)
XMLUnit.setIgnoreWhitespace(true)
XMLUnit.setIgnoreComments(true)
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true)
XMLUnit.setNormalizeWhitespace(true)

DetailedDiff myDiff = new DetailedDiff(new Diff(xml1, xml2));
List allDifferences = myDiff.getAllDifferences();

allDifferences.each { difference ->
    log.info (difference)
}
编辑:通过实验,我得出以下结论:

List allDifferences = myDiff.getAllDifferences();
这就是为什么会弹出对话的原因。我猜getAllDifferences()方法会导致弹出对话框


我仍然需要一些帮助来确定一个可行的替代方案,因为我正在尝试比较两个xml文件并在一个文件中打印差异。

这不是XMLUnit类的问题(
Diff
DetailedDIff
等等),这是与SOAPUI中的groovy脚本测试步骤相结合的
groovy
的行为:在
groovy
语言中,如果未指定
return
,则最后计算的表达式是默认返回值,因此,当Groovy脚本测试步骤单独执行时,SOAPUI会捕获
返回值
,如果它不是
null
,则会打印字符串对象表示(如果作为测试用例的一部分执行Groovy测试步骤,则不会发生这种情况,因为SOAPUI脚本不会捕获并显示
返回值
)。i、 e如果在SOAPUI上执行下一个groovy脚本:

def a = 3 + 1
groovy
正在添加
return
,因此您确实有:

def a = 3 + 1
return a
和SOAPUI捕获此
返回
,并显示下一个对话框:

因此,您可以修复此行为,在末尾将
null
分配给某个变量,或者添加
return
nothing,如下所示:

import groovy.io.FileType;
import org.custommonkey.xmlunit.*;

...

DetailedDiff myDiff = new DetailedDiff(new Diff(xml1, xml2));
List allDifferences = myDiff.getAllDifferences();

allDifferences.each { difference ->
    log.info (difference)
}

// ADD THIS LINE TO AVOID DIALOG BOX
def dontCare = null; // groovy add return dontCare :)
或:


希望这有帮助,

弹出窗口是什么样子的?它是一个带有标签“information”的信息对话框。内容是来自行日志的内容。info(不同之处)(即日志中由于此行而输出的所有内容也在对话框中)。然后有一个按钮显示“OK”。结果表明,我可以通过在循环后添加log.info“Done”来消除弹出窗口,尽管我不确定问题得到解决的原因。如果在初始化变量后断言它,这将消失。谢谢!这解决了我的问题
import groovy.io.FileType;
import org.custommonkey.xmlunit.*;

...

DetailedDiff myDiff = new DetailedDiff(new Diff(xml1, xml2));
List allDifferences = myDiff.getAllDifferences();

allDifferences.each { difference ->
    log.info (difference)
}

// ADD THIS LINE TO AVOID DIALOG BOX
return;