Overview
This page covers WebSocket testing functionality in Artillery provided by the built-in WebSocket engine.
Enabling WebSocket support
To use the WebSocket engine in an Artillery scenario, set the engine
attribute of a scenario definition to ws
.
scenarios: |
WebSocket-specific configuration
Setting Subprotocols
WebSocket subprotocols may be configured with config.ws.subprotocols
option:
config: |
Specifying Headers
Connection headers may be specified via config.ws
object. For example, to set a custom subprotocol via the Sec-WebSocket-Protocol
header:
config: |
Other configuration options
The underlying WebSocket client can be configured with a "ws"
section in the "config"
section of your test script. For a list of available options, please see WS library docs.
Scenario actions and configuration
Four types of actions are supported: send
, think
, loop
, and function
.
Sending data with send
Use send
to send data to the server:
If the argument is an object, it will be converted to a string with JSON.stringify
before being sent.
- send: "a string" |
Pausing execution with think
To pause the virtual user for N seconds, use a think
action:
- send: "hello" |
Repeating actions with loop
See Testing HTTP for a detailed description of the loop
action.
Running custom code with function
Custom JS code may be run with the function
action:
config: |
// my-functions.js |
Example
config: |