Diff XML files in SoapUI with Groovy, ignoring GUID and timestamp differences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = context.testCase.name.toLowerCase() | |
def testSuite = context.testCase.testSuite.name | |
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() | |
results.waitFor() | |
assert results.exitValue() == 0 | |
results.destroy() | |
} | |
} |
Hi,
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.
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
http://spin.atomicobject.com/2011/01/21/diff-not-that