WebSocket Plugin
The plugin provides a functionality to interact with WebSocket.
Installation
-
Copy the below line to
dependencies
section of the projectbuild.gradle
filePlease make sure to use the same version for all VIVIDUS dependencies. Example 1. build.gradleimplementation(group: 'org.vividus', name: 'vividus-plugin-websocket', version: '0.6.2')
-
If the project was imported to the IDE before adding new dependency, re-generate the configuration files for the used IDE and then refresh the project in the used IDE.
Properties
It’s allowed to configure an unlimited number of WebSocket connections via the mechanism of the dynamic properties. The properties example is:
websocket.connection.chat=ws://websocket.chat.com/
websocket.connection.debug=ws://localhost:54886/
where chat
and debug
are keys used to refer websocket connections in the steps. The keys are defined by users, must be unique and can’t contain dots.
Steps
Connect
Creates a new websocket connection.
When I connect to `$webSocketConnectionKey` websocket
-
$webSocketConnectionKey
- the websocket connection key
When I connect to `chat` websocket
Send text message
Sends a text message over the websocket.
When I send text message `$message` over `$webSocketConnectionKey` websocket
-
$message
- the text message to send -
$webSocketConnectionKey
- the websocket connection key
When I send text message `Hi everyone` over `chat` websocket
Disconnect
Disconnects from an existing websocket. All the received text messages are kept and can be drained into the variable using the drain step.
When I disconnect from `$webSocketConnectionKey` websocket
-
$webSocketConnectionKey
- the websocket connection key
When I disconnect from `chat` websocket
Wait for text messages
Waits until the count of the text messages received over the specified websocket matches to the rule or until the timeout is exceeded.
When I wait with `$timeout` timeout until count of text messages received over `$webSocketConnectionKey` websocket is $comparisonRule `$expectedCount`
-
$timeout
- the maximum time to wait for the messages in ISO-8601 Durations format. -
$webSocketConnectionKey
- the websocket connection key. -
$comparisonRule
- the comparison rule. -
$expectedCount
- the expected count of the messages to be matched by the rule.
When I wait with `PT30S` timeout until count of text messages received over `chat` websocket is equal to `1`
Drain text messages
Drains the text messages received over the specified websocket to the specified variable. If the websocket is not disconnected, the new messages might arrive after the draining. If the websocket is disconnected, all the messages received after the websocket is connected or after the last draining operation are stored to the variable.
When I drain text messages received over `$webSocketConnectionKey` websocket to $scopes variable `$variableName`
-
$webSocketConnectionKey
- the websocket connection key -
$variableName
- the variable name to store the messages. The messages are accessible via zero-based index, e.g.${my-var[0]}
will return the first received message.
When I drain text messages received over `chat` websocket to scenario variable `welcomeMessages`
Then `${messages[0]}` is equal to `Hi Jetty`