gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:49:13 24 4
gpt4 key购买 nike

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

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();

是弹出对话框的原因。我猜测 getAllDifferenes() 方法导致弹出对话框。

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

最佳答案

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

def a = 3 + 1

groovy 正在添加 return,因此您确实拥有:

def a = 3 + 1
return a

SOAPUI 捕获此返回并显示下一个对话框:

Groovy script dialog box

因此,您可以修复此行为,在最后将 null 分配给某个变量,或者显式添加 return 任何内容,如下所示:

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 :)

或者:

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;

希望这有帮助,

关于groovy - 在比较两个 xml 文件并记录差异时,SoapUI log.info 由于某种原因打开对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24575835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com