What you’ll learn
- How to add assertions and expectations to HTTP scenarios with
artillery-plugin-expect
plugin
Overview
The artillery-plugin-expect
plugin can be used to add expectations/assertions to your HTTP scenarios to allow for the same scenarios to be re-used forrunning both load tests and functional/acceptance tests.
Usage
Install the plugin
npm install -g artillery-plugin-expect
Enable the plugin in the config section
config:
target: "http://example.com"
plugins:
expect: {}
Use expectations on your requests
scenarios:
- name: Get pets
flow:
- get:
url: "/pets"
capture:
- json: "$.name"
as: name
expect:
- statusCode: 200
- contentType: json
- hasProperty: results
- equals:
- "Tiki"
- "{{ name }}"
Expectations
statusCode
Check that the response status code equals the code given.
expect:
- statusCode: 201
contentType
Check the value of Content-Type
header.
hasProperty
and notHasProperty
When the response is JSON, check that the response object has a property (or does not in case of notHasProperty
). Same behavior as lodash#has
.
expect:
- hasProperty: 'data[0].id'
equals
Check that two or more values are the same. NOTE only primitive values (e.g. booleans, strings and numbers) are currently supported.
- get:
url: "/pets/f037ed9a"
capture:
- json: "$.species"
as: species
expect:
- equals:
- "{{ species }}"
- "dog"
hasHeader
Check that the response contains a header.
- get:
url: "/pets/f037ed9a"
expect:
- hasHeader: "object-version"
headerEquals
Check that the response contains a header and its value matches some string.
- get:
url: "/pets/f037ed9a"
expect:
- headerEquals:
- "object-version"
- "v3"
matchesRegexp
Check that response body matches a regular expression. The regular expression provided must be a string which is a valid argument to the RegExp constructor.
- get:
url: "/pets/f037ed9a"
expect:
- matchesRegexp: .+ # body is not empty
More Information
The source code for artillery-plugin-expect
is available on Github at https://github.com/shoreditch-ops/artillery-plugin-expect. It’s an officially supported plugin and we’d love to hear your feedback and ideas for improvement.