0

I'm comparing two xml in soapUi (Groovy) and I want to ignore some tags (not just one)

I tried this solution below but didn't work :

def ExpectedString = 'Expected Xml'
def ResponseString ='XML SoapResponse to compare'

Diff diff = DiffBuilder.compare(ExpectedString)
           .withTest(ResponseString)
           .ignoreComments()
           .ignoreWhitespace()
           .checkForSimilar()
           .withNodeFilter{node -> !node.getNodeName().equals('somerandomstuff')}
           .withNodeMatcher(new DefaultNodeMatcher(new ByNameAndTextRecSelector(),
ElementSelectors.byNameAndText))
           .build()

Something wrong with my code ? I get this error :

No signature of method: org.xmlunit.builder.DiffBuilder.withNodeFilter() 
is applicable for argument types: (Script4$_run_closure2) values: 
[Script4$_run_closure2@2ea2e326] Possible solutions: 
withNodeFilter(org.xmlunit.util.Predicate)

Thanks !

Hamza Amami
  • 94
  • 4
  • 21
  • My groovy is a little rusty but don't you need curly braces around your closures? As in `{ node -> !node.getNodeName().equals('somerandomstuff') }` - or even `{ !it.NodeName == 'somerandomstuff' }`? – Stefan Bodewig Nov 26 '16 at 06:04
  • @StefanBodewig True ! but now i've got this : No signature of method: org.xmlunit.builder.DiffBuilder.withNodeFilter() is applicable for argument types: (Script3$_run_closure2) values: [Script3$_run_closure2@594c518c] Possible solutions: withNodeFilter(org.xmlunit.util.Predicate) – Hamza Amami Nov 28 '16 at 07:32
  • it may depend on the version of Groovy you are using. You may need to explicitly cast the closure to a `Predicate` as in `{ node -> !node.getNodeName().equals('somerandomstuff') } as org.xmlunit.util.Predicate` - http://docs.groovy-lang.org/latest/html/documentation/core-semantics.html#closure-coercion says the `as` part has become obsolete with Groovy 2.2.0. – Stefan Bodewig Nov 29 '16 at 11:38

0 Answers0