At Assertible, we work with APIs and other web services in all shapes and sizes. Although JSON is practically a standard in new public APIs, XML is still an extremely widely used markup language and serialization format; especially in legacy APIs and specific industries. XML is also widely used in the form of HTML web pages.
Our shiny new XPath XML/HTML data assertion is capable of extracting values from XML and HTML documents and comparing the value to hard-coded data and dynamic variables. This functionality opens up a lot of new ways to automate tests for your API or website.
XPath for XML payloads
Extracting values from XML payloads and making assertions about them is straight-forward. One thing to keep in mind is that the XPath XML assertion only supports selecting a single node. For example, using the following payload:
<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="cooking"> <title lang="en">Everyday Italian</title> </book> <book category="children"> <title lang="en">Harry Potter</title> </book> <book category="web"> <title lang="en">XQuery Kick Start</title> </book> <book category="web"> <title lang="en">Learning XML</title> </book> </bookstore>
Valid XPath selection:
This selection is valid because it plucks the first node in the list of books. Keep in mind that array indexes in XPath start at
Invalid XPath selection:
This selection is not valid because it returns a list of nodes as the result. In the future, we plan to add support for multiple-node selections.
For more examples, see our XPath assertion examples
XPath for HTML pages
One great use-case for the XPath assertion is working with HTML website pages. Using Chrome Dev Tools, you can automatically copy XPath selectors that will help you create assertions for your website easily. Simply open Chrome Dev Tools, click Elements, right click on an HTML node, and select Copy XPath.
Naturally, if you're working with an XML API or HTML website, you may have complex tests which require chaining HTTP requests and creating dynamic variables. For this, you would use Assertible's setup steps. However, setup steps only support JSON Path selection (as of 2017-07-20).
No worries! we are working to fix this and will publish another changelog blog post when we have something you can try out.
This is just the start of many improvements we plan on making to Assertible. Have an idea for how we can improve the API testing experience? Shoot me a message on Twitter or reach out directly and let's chat!
:: Christopher Reichert
The easiest way to test and
monitor your web services
Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.Get started with GitHubSign up for free
New feature: Encrypted variables 10/30/2019
New feature: Smarter notifications 5/17/2019