New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default match by name with differently sorted elements doesn't work #197
Comments
Actually my intention was - and so far I assumed I had implemented it that way :-) - that using |
hmm, the tests I've added pass and import org.xmlunit.diff.*;
import org.xmlunit.builder.DiffBuilder;
public class Test197 {
public static void main(String[] args) throws Exception {
Diff ds = DiffBuilder.compare("<root><a>foo</a><a>bar</a></root>")
.withTest("<root><a>baz</a><a>foo</a></root>")
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors
.selectorForElementNamed("a", ElementSelectors.byNameAndText),
ElementSelectors.byName))
.build();
for (Difference d : ds.getDifferences()) {
System.err.println(d.toString());
}
}
} prints
which is what I expected. Something must be different in your case. |
Yes, this is because first element in control is found, but if you switch control and test:
Prints out:
|
Ah, good catch, thank you. |
should be fixed in the main branch, I'll publish 2.8.0-SNAPSHOT builds in a few minutes |
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):
Works for:
Causing TEXT_VALUE difference of second a element.
But if the order is different (so that first element is not matched using first selector):
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.
The text was updated successfully, but these errors were encountered: