Skip to content

Default match by name with differently sorted elements doesn't work #197

@tavorjeremic

Description

@tavorjeremic

Hi,
I am struggling to create solution for matching elements by name and text and fall back to name if not found when elements have different order.

Given example in documentation (https://github.com/xmlunit/user-guide/wiki/SelectingNodes#using-more-than-one-elementselector-at-the-same-time):

new DefaultNodeMatcher(ElementSelectors.selectorForElementNamed("a", ElementSelectors.byNameAndText), ElementSelectors.byName)

Works for:

<root>
  <a>foo</a>
  <a>bar</a>
</root>
<root>
  <a>foo</a>
  <a>baz</a>
</root>

Causing TEXT_VALUE difference of second a element.

But if the order is different (so that first element is not matched using first selector):

<root>
  <a>bar</a>
  <a>foo</a>
</root>
<root>
  <a>foo</a>
  <a>baz</a>
</root>

This will match first element in control with first element in test causing 2 differences.

If we provide only byNameAndText selector then we get CHILD_LOOKUP instead of TEXT_VALUE difference.

Is there any way to match first by some condition (like byNameAndText) ALL elements (in both control and test) and then only to match by name what is left unmatched?

From what i gathered the issue is that comparison is trying to match first element in control with all from test using first selector, then using second selector and only then it goes to second element in control so either first element will be incorrectly matched or it will be marked as non existing instead of having different value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions