Karate: Dynamic XPaths with count() fail with karate.xmlPath()

Created on 23 Apr 2019  Â·  4Comments  Â·  Source: intuit/karate

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:

  • Numerical values associated with XPath count() queries
  • String values associated with the text inside elements

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.

bug fixed

All 4 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ampc picture ampc  Â·  5Comments

raveendaranugu picture raveendaranugu  Â·  3Comments

jmcelwain picture jmcelwain  Â·  4Comments

JuliaSv picture JuliaSv  Â·  5Comments

bbchristians picture bbchristians  Â·  4Comments