Web Socket Protocol

Any service that uses the Web Socket protocol can be tested with Testable, including protocols like SockJS and Socket.io which use HTTP as a fallback. When creating a new test target use the following URL formats:

ws://sample.testable.io/streaming/websocket
ws://ws.websocketstest.com/service
wss://wss.websocketstest.com/service
http://mydomain/sockjs-endpoint

Example

Note that an HTTP gateway will also accept websocket connections and you can distinguish the traffic using the Type column on the recording.

Scripts

If you choose to define your scenario by writing a script you have access to the 'ws' npm module.

Recordings

Here is an example of a recording that uses the Testable Sample Service's websocket endpoint at ws://sample.testable.io/streaming/websocket. This endpoint supports both the SockJS protocol at /streaming and binary frames over a raw websocket at /streaming/websocket.

Recording

The gateway URL to capture the recording is ws://{key}.gateway.testable.io/streaming/websocket which acts as a MITM recording proxy to ws://sample.testable.io/streaming/websocket. The key in the gateway URL will be different when you try this on your own Testable account.

If you click on the connection the packets grid below will show you all the traffic send/received over the connection (the Packets Grid also updates in real time).

Recording

To capture the traffic for the recording, we used the following Javascript code in the browser (Chrome):

<script>
    var sock = new WebSocket('ws://{key}.gateway.testable.io');
    sock.onopen = function() {
        sock.send(JSON.stringify({ subscribe: "IBM" }))
    };
    sock.onmessage = function(e) {
        var reader = new FileReader();
        reader.onload = function(event){
          console.log('On Message: ' + JSON.stringify(reader.result));
        };
        reader.readAsText(e.data);
    };
    sock.onclose = function() {
        console.log('close');
    };
</script>

Tests

During test execution the recorded steps will be replayed. The agent will use the traffic received from the server to decide how long to wait for incoming packets and whether or not the test succeeded.

Results

The platform captures a variety of stats for each websocket opened during test execution. Additional custom metrics can be added by first converting the recording into a script.