kbw's avatar
kbw
Contributor
9 years ago
Status:
New Idea

Make wild-cards in assertions pass for elements without any content

Currently, if you write an xpath assertion with wildcards enabled, then when you have an element with the wildcard for its contents, but it is actually returned empty, then assertion fails.

 

It should not flag as a failure--the wildcard means that we don't care what is in the element, including nothing, as long as the element is present.


Please enhance/fix the wild-cards to pass in this scenario.

 

Example:

 

You have a JDBC test step that returns this:

[...]

<SOMETAG>ExpectedData</SOMETAG>

<SOMEOPTIONALINFO/>

[...]

 

And your xpath assertion includes something like this:

[...]

<SOMETAG>ExpectedData</SOMETAG>

<SOMEOPTIONALINFO>*</SOMEOPTIONALINFO>

[...]

 

Then currently, this validation fails.  However, it really should pass, since the wildcard was used.

 

1 Comment

  • kbw's avatar
    kbw
    Contributor

    FYI: I've got a workaround for this. and decided that having the wild-card fail for empty elements does have it's uses (e.g. test that the element is present and always has some data, but it never empty).  So I'd still like this enhancement, but with an option in the assertion for whether to have the wildcard treat an empty element as a pass or fail (when the wildcard is the ONLY contents of the element).

     

    But, since we have an easy workaround, this enhancement's not as important.

     

    The workaround is simple: In this situation, just have your expected result reference the contents of the element under test itself. Unlike the wildcard, this will also pass when the tested element is present and empty.

     

    For example, using my example in the original post, here's the expected result:

    <SOMEOPTIONALINFO>${ResultAsXml#//SOMEOPTIONALINFO[1]}</SOMEOPTIONALINFO>