Skip to content
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

Matchers.hasXPath should handle valueMatcher against multiple elements #323

Open
fabian-froehlich opened this issue Jan 4, 2021 · 1 comment · May be fixed by #337
Open

Matchers.hasXPath should handle valueMatcher against multiple elements #323

fabian-froehlich opened this issue Jan 4, 2021 · 1 comment · May be fixed by #337

Comments

@fabian-froehlich
Copy link

fabian-froehlich commented Jan 4, 2021

It seems convinient to have a XPath-Matcher that is not limited to only look into the first matched element for the XPath

Example-XML:

<books>
    <book>
        <isbn>A-ISBN</isbn>
        <name>A-Book</name>
    </book>
    <book>
        <isbn>B-ISBN</isbn>
        <name>B-Book</name>
    </book>
</books>

will not be accpeted by the assert
assertThat(xml, hasXPath("/books/book/isbn", is(equalTo("B-ISBN"))));

Expected: an XML document with XPath /books/book/isbn is "B-ISBN"
     but: mismatches were: [an XML document with XPath /books/book/isbn is "B-ISBN" was "A-ISBN"

But this should match because the book with B-ISBN exists.

A workaround would be to leave out the valueMatcher and put the value into the XPath
assertThat(actualDocument, hasXPath("/books/book/isbn[text()='B-ISBN']"));
which will correctly match the existence but at costs of a poorly explaining error message. This makes it harder identify whether your test is broken or your system-under-test.

@fabian-froehlich fabian-froehlich changed the title Make hasXPath apply valueMatcher against multiple elements Matchers.hasXPath should handle valueMatcher against multiple elements Jan 4, 2021
@night-gale night-gale linked a pull request Apr 25, 2021 that will close this issue
@night-gale
Copy link

Hi, I am currently working on this issue @nhojpatrick , and had a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants