Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2011 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karlin/789830 to your computer and use it in GitHub Desktop.
Save karlin/789830 to your computer and use it in GitHub Desktop.
Diff XML files in SoapUI with Groovy, ignoring GUID and timestamp differences
// In each testcase script assertion:
import FileCompare
FileCompare.compareWithExpected(context, messageExchange)
// In our Script Library:
package filecompare
class FileCompare {
def static compareWithExpected(context, mex) {
def testCase =
def testSuite =
def projectDir = new File(context.testCase.testSuite.project.path).parent
def expectedFilename = "$projectDir/expected_responses/${testSuite}/${testCase}"
def gotFilename = "${expectedFilename}_got.xml"
new File(gotFilename).write(mex.responseContentAsXml)
def ignoreGUIDs = "-I \"[0-9a-f]\\{32\\}\""
def ignoreDates = "-I \"[0-9]*\\/[0-9]*\\/[0-9]\\{4\\}\""
def diffCmd = "diff -bq --strip-trailing-cr $ignoreGUIDs $ignoreDates ${expectedFilename}.xml $gotFilename"
def results = diffCmd.execute()
assert results.exitValue() == 0
Copy link

karlin commented Jan 21, 2011

Copy link


Recently started using groovy for soapui automation . As part of this, i need to compare expected xml file with soap response xml. Some of the node values in xml are dynamic.

Error message

Getting an error at "def results = diffCmd.execute()".
Do i need to import any package to resolve the issue ? and how to print xml difference value to console?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment