2

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.

albciff
  • 18,112
  • 4
  • 64
  • 89
MKhowaja
  • 62
  • 1
  • 10
  • what does the popup look like? – Abhishek Asthana Jul 07 '14 at 16:52
  • It's an information dialogue box with the Label "Information" The contents are the contents from the line log.info(difference) (ie everything outputted in the log due to this line is also in the dialog box). Then there is a button that says "OK." It turns out that I can eliminate the popup by adding a log.info "Done" after the loop although I wasn't sure why the issue was resolved. – MKhowaja Jul 07 '14 at 17:55

1 Answers1

6

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:

Groovy script 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,

albciff
  • 18,112
  • 4
  • 64
  • 89