I am trying to invoke dynamic XPaths in Karate v0.9.2 via the Scripting API, karate.xmlPath().
My basic XPath queries for retrieving XML elements (Nodes, NodeLists, Attributes etc) work,
BUT queries attempting to retrieve non-Node/non-NodeList elements fail.
For example:
Actual result:
In the case of the count() queries a typical error generated is of the form:
com.intuit.karate.exception.KarateException: users.feature:51 - javascript evaluation failed: karate.xmlPath(testUsers,xpathQuery), javax.xml.xpath.XPathExpressionException: com.sun.org.apache.xpath.internal.XPathException: Can not convert #NUMBER to a NodeList!
at ✽.* def userCount = karate.xmlPath(testUsers,xpathQuery) (users.feature:51)
Expected Result:
I would expect that the dynamic scripting XPath API could return not just NodeList results but also simple/primitive values (eg, Integer/Double, String, Boolean).
The attached project exercise such a scenario with a simple XML dataset.
GitHub sample project:
Related Stack Overflow:
https://stackoverflow.com/questions/55743105/how-to-invoke-dynamic-xpaths-with-count-in-karate
@mhavilah thanks for the report, would you be able to build from source and confirm that this is indeed fixed ?
I've just built the "v1.0.0" pre-release build on the development branch.
Happy to confirm the failing test I had for the dynamic XPath count() scenario now goes green.
Keep up the great work and congratulations on such a great framework. :-)
@mhavilah great to hear that ! I'll keep this open until we release the next version which should be 0.9.3
released 0.9.3