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

Added support for XPath and DOMParser #32

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

christophe-pietquin
Copy link

This merge request adds support for XPath in order to allow testing REST/XML APIs in Newman using XPath

@shamasis
Copy link
Member

@christophe-pietquin - i see the value in XPath (and probably JPath), but XMLDom is too heavy to be loaded everytime (and we are already struggling to remove backbone and other less relevant packages now.) We have cheerio to do the same thing as XMLDom and is already very popular. Let me know your thoughts.

@shamasis shamasis self-assigned this Feb 14, 2017
@christophe-pietquin
Copy link
Author

@shamasis I understand your concern about heaviness. The question is than how would you write a test script with xpath assertions that would run in both Postman and Newman if using cheerio?

This merge request allow us to create test script like the following one which detects if it is ran from Postman or Newman and uses the proper objects to execute the xpath queries:

xmlDoc = new DOMParser().parseFromString(responseBody, 'text/xml');
var xpathImpl;
var XPathResultImpl;
if (typeof xpath != "undefined") {
   xpathImpl = xpath;
XPathResultImpl = xpath.XPathResult;

} else { 
xpathImpl = document; 
 XPathResultImpl = XPathResult;
}
var docs = xpathImpl.evaluate("/response/results/total", xmlDoc, null, XPathResultImpl.STRING_TYPE, null); 
tests["total number of matching documents is returned"] = docs.stringValue.toLowerCase() === '1'; 

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