SoapUI log.info opens dialogue box for some reason when comparing two xml files and logging the differences

江枫思渺然 提交于 2019-12-24 05:09:04

问题


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.


回答1:


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,



来源:https://stackoverflow.com/questions/24575835/soapui-log-info-opens-dialogue-box-for-some-reason-when-comparing-two-xml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!