Artillery Expectation Plugin

2.24.0 · active · verified Wed Apr 22

Artillery-plugin-expect is an official plugin for Artillery, a powerful open-source load and functional testing tool built with Node.js. This plugin extends Artillery's capabilities by adding support for declarative checks and assertions on HTTP requests directly within YAML test scripts. It enables users to perform functional or acceptance testing alongside performance testing, verifying response status codes, content types, headers, body properties (via JSONPath or JMESPath), and regex matches. The current stable version is 2.24.0, and its development and release cadence are now tightly integrated with the main Artillery project since its codebase was moved into the core repository in December 2022. This plugin is a key differentiator for Artillery, allowing comprehensive API testing (both load and functional) from a single, YAML-driven test definition, making it suitable for CI/CD pipelines to run post-deployment smoke tests.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `artillery-plugin-expect` globally and configure a basic Artillery YAML script. It shows how to enable the plugin and add various HTTP expectations (status code, content type, body properties, equality, regex matching) to different request steps within a scenario, including using captured variables in assertions. It also illustrates how to use environments to switch between functional and load testing.

npm install -g artillery artillery-plugin-expect

# Create a file named 'test-api.yml'
# The following YAML defines a simple functional test scenario
# using artillery-plugin-expect.
# It targets a placeholder API and asserts on the response.
---
config:
  target: 'https://jsonplaceholder.typicode.com'
  plugins:
    expect: {}
  environments:
    functional:
      phases:
        - duration: 1
          arrivalCount: 1
    load:
      phases:
        - duration: 10
          arrivalRate: 5

scenarios:
  - name: Get A Todo Item
    flow:
      - get:
          url: '/todos/1'
          expect:
            - statusCode: 200
            - contentType: json
            - hasProperty: 'id'
            - hasProperty: 'title'
            - equals:
                - 'delectus aut autem'
                - '{{ body.title }}'
            - matchesRegexp:
                - 'autem'
                - '{{ body.title }}'
      - get:
          url: '/posts/1'
          capture:
            - json: '$.title'
              as: postTitle
          expect:
            - statusCode: 200
            - contentType: json
            - equals:
                - 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
                - '{{ postTitle }}'

# Run the functional test:
# artillery run --environment functional test-api.yml

# Or run a load test (without plugin output):
# artillery run --environment load test-api.yml

view raw JSON →