比较两个xml文件并记录差异时,SoapUI log.info会出于某种原因打开对话框 [英] SoapUI log.info opens dialogue box for some reason when comparing two xml files and logging the differences

查看:132
本文介绍了比较两个xml文件并记录差异时,SoapUI log.info会出于某种原因打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

def file1 =somepath / file1.xml
def file2 =somepath / file2.xml
$ b $ def xml1 = new FileReader(file1)$ b (true)
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true)
XMLUnit.setNormalizeWhitespace(true)$ b $ x $ b $

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

allDifferences.each {差异 - >
log.info(区别)
}

编辑:通过实验,我找出以下内容:

  List allDifferences = myDiff.getAllDifferences(); 

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



因为我试图比较,所以我仍然想帮助确定一个可行的替代方案两个xml文件并在文件中打印差异。 这对于XMLUnit类( Diff DetailedDIff 等等),这就是 groovy 连接的行为在SOAPUI中使用Groovy脚本测试步骤:如果未指定 return ,则在 groovy 语言中,则最后一个评估表达式是默认的返回值,所以当Groovy脚本测试步骤中,它独自执行SOAPUI,捕获 return ,如果它不是 null 打印字符串对象表示(如果你执行groovy测试步骤作为测试用例的一部分,这不会发生,因为SOAPUI脚本没有捕获并显示 return )。即如果你在SOAPUI上执行下一个groovy脚本:

  def a = 3 + 1 

groovy 正在添加 return ,所以你真的有:

  def a = 3 + 1 
返回a

SOAPUI捕获 return 并显示下一个对话框:





所以你可以在最后加上 return 来修改这个行为,给一些变量赋一个 null 没有任何明确的说明如下:

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

...

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

allDifferences.each {差异 - >
log.info(区别)
}

//添加此行以避免对话框
def dontCare = null; // groovy add return dontCare :)

或者:

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

...

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

allDifferences.each {差异 - >
log.info(区别)
}

//添加此行以避免对话框
return;

希望这有助于您,


For some reason the following script when executed, prints the output not only in the log but also in an information pop-up dialogue box. Can someone explain to me why this occurs and how I can prevent it from happening?

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

EDIT: Through experimentation, I figured out that the following line:

List allDifferences = myDiff.getAllDifferences();

is the reason why the dialogue pops up. I am guessing that the getAllDifferenes() method is causing the dialogue pop up to occur.

I would still like some help to determine a viable alternative since I am trying to compare two xml files and print the differences in a file.

解决方案

This is not a problem with XMLUnit classes (Diff, DetailedDIff and so on), this is the behavior of groovy in conjuntion with Groovy script test step in SOAPUI: In groovy language if you doesn't specify a return then the last evaluated expression is the default return value, so when Groovy script test step it executes alone the SOAPUI catch the return and if it's not null prints the string object representation (if you execute the groovy test step as part of test case this not happens because SOAPUI script doesn't catch and show the return). i.e if you execute the next groovy script on SOAPUI:

def a = 3 + 1

groovy is adding return, so you really have:

def a = 3 + 1
return a

And SOAPUI catch this return and shows the next dialog box:

So you can fix this behavior assigning a null to some variable at the end either adding return nothing explicitly as follows:

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

Or:

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;

Hope this helps,

这篇关于比较两个xml文件并记录差异时,SoapUI log.info会出于某种原因打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆