Run WebSocket messages

Tricentis Tosca API Scan enables you to run WebSocket (WS) messages using a WebSocket connection. Additionally, you can scan a RAML file that contains WebSocket defintions as described in chapter "Use RAML for Websocket definition".

WebSocket support allows you to perform the following actions:

  • Connect to a WebSocket server.

  • Send and receive WebSocket messages.

  • Get information about the total number of messages your WebSocket client receives from the WebSocket server.

When you scan a WebSocket URI, we pregenerate the WebSocket-specific message types (Connect, Disconnect, Info, Receive, and Send) for your convenience.

After running your WebSocket messages in API Scan, you can export them to Tosca Commander, and use the message information to define Module Attributes and verify their values. Depending on your tests, export the messages as an API or XML/JSON TestCase, as appropriate.

Connect to a WebSocket server

To connect to a WebSocket server, follow the steps below:

  1. Create a message from a URI.

  2. Select a WebSocket connection from the Connection dropdown menu.

  3. Select Connect from the Method dropdown menu.

    Alternatively, select the CONNECT message from the pregenerated message list.

Select Connection and Method

  1. Click the API Test Case button on the ribbon to convert your project into a Test Case for Tosca.

  2. Run your TestCase in Tosca.

Send WebSocket messages

To send WebSocket messages, follow the steps below

  1. Create a message from a URI.

  2. Select a WebSocket connection from the Connection dropdown menu.

  3. Select Send from the Method dropdown menu.

    Alternatively, select the SEND message from the pregenerated message list.

Select Connection and Method

  1. Click the API Test Case button on the ribbon to convert your project into a Test Case for Tosca.

  2. Run your TestCase in Tosca.

Receive WebSocket messages

To receive WebSocket messages, follow the steps below

  1. Create a message from a URI.

  2. Select a WebSocket connection from the Connection dropdown menu.

  3. Select Receive from the Method dropdown menu.

    Alternatively, select the RECEIVE message from the pregenerated message list.

Select Connection and Method

  1. Click the API Test Case button on the ribbon to convert your project into a Test Case for Tosca.

  2. Run your TestCase in Tosca.

Retrieve WebSocket information

You can retrieve WebSocket message-related information for the following purposes:

  • Get the number of messages sent to a WebSocket server during a connection

  • Find our how many WebSocket messages met the filter criteria you set as ModuleAttributes in your TestCase

There are a number of limitations that apply and you have to consider when designing TestCases around the WebSocket information retrieval:

  • Both parameters (Number of all messages and Number of messages matching a filter) default to the Verify ActionMode.

  • The WaitOn ActionMode does not work for the Number of all messages and Number of messages matching a filter parameters, as it uses the Module TechnicalView of the message itself

  • Setting the ActionMode to Insert or Input is not applicable for the Number of all messages and Number of messages matching a filter parameters

  • When using a Path or Query parameter, you have to ensure that the ActionMode is set to Insert

  • For all other business parameters, the default ActionMode is WaitOn, which becomes a part of the query when counting messages

To retrieve WebSocket message information, follow the steps below:

  1. Create a message from a URI.

  2. Select a WebSocket connection from the Connection dropdown menu.

  3. Select Info from the Method dropdown menu.

    Alternatively, select the INFO message from the pregenerated message list.

    Select Connection and Method

  4. Click the API Test Case button on the ribbon to convert your project into a Test Case for Tosca.

    On the Channel Info tab, you can see how many messages were received and how many messages matched your filter criteria (if set).

    Number of messages received from WebSocket via API Scan

Disconnect from a WebSocket server

By default, WebSocket disconnects at the end of a TestCase. You can, however, implement a specific Disconnect method to stop a WebSocket connection from receiving messages while leaving the already-received messages available for verification purposes.

If you reopen a previously closed connection, the previously received messages are deleted.

To disconnect from a WebSocket server, follow the steps below:

  1. Select an existing WebSocket connection from the Connection dropdown menu.

  2. Select Disconnect from the Method dropdown menu.

    Alternatively, select the DISCONNECT message from the pregenerated message list.

Select Connection and Method