Expectations and Assertions (HTTP)

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

When the response is JSON, check that the response object has a property. Same 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"

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.