07/25/2017 Changelog Christopher Reichert

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.

Because of XML's ubiquity, we have officially added support for XPath, a query language for selecting nodes from an XML or HTML document.

Assertible XPath assertions for HTML and XML

Read the XML/HTML assertion docs

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"?>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
  <book category="children">
    <title lang="en">Harry Potter</title>
  <book category="web">
    <title lang="en">XQuery Kick Start</title>
  <book category="web">
    <title lang="en">Learning XML</title>
  • Valid XPath selection: /bookstore/book[1]

    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 [1].

  • Invalid XPath selection: /bookstore/book

    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.

Chrome Dev Tools copy XPath

Next steps

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!

Start testing your API for free

:: Christopher Reichert


The easiest way to test and
monitor your web services

Define and test your web service with Assertible Track and test API deployments across environments Schedule API monitoring and failure alerts

Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.

Sign up for free