testing web pages with hurl
hurl
is a commandline utility built on top of CURL
that can run super-quick tests on your rendered web assets by not needing to spin up a headless browser. It can quickly grab and check things like:
- HTTP status
- HTTP version
- response headers
- any HTML content queryable with XPath
- XML and JSON APIs
- ...much more.
It will happily run any HTTP method, and supports all the things you'd expect CURL to support as far as options.
It supports assertions so you can roll it into your CI/CD processes.
Here's an example test:
# test.hurl
# double hit to prime varnish cache
GET https://www.insidenewcity.com/
GET https://www.insidenewcity.com/
HTTP/2 200
[Asserts]
#has a populated title
xpath "string(//head/title)" contains "NewCity"
#has blog articles
xpath "//article" count > 1
#is cached
header "x-cache" contains "HIT"
This example verifies that we're running over HTTP 2, and we're getting a successful page load (200). It then checks our document title, that there are articles loading, and that the page itself is being cached by Varnish (this is why there are two page loads). You can add more URLs and asserts directly in the same file, just keep adding lines.
This can be called in CI/CD via hurl --test test.hurl
.
Output looks like:
test.hurl: Running [1/1]
test.hurl: Success (2 request(s) in 222 ms)
--------------------------------------------------------------------------------
Executed files: 1
Succeeded files: 1 (100.0%)
Failed files: 0 (0.0%)
Duration: 223 ms
Gitlab has a great article about how to use this on their platform.