JavaScript API

The Module for WebSocket Testing adds a new object websocket to WAPT Pro JavaScript API. You can use it in JavaScript-operators and JavaScript-functions. This object has a method send and a property response.

"Send" method

Using the send method, you can send a message to the certain WebSocket connection.

The syntax of "send" method:

websocket.send(string websocketConnectName, string body, bool isText)

Here "websocketConnectName" is the name of WebSocket connection and "body" is message body. Both parameters are strings.
The last parameter "isText" can be true or false.

If "isText" is true, then the string "body" must contain a message in the text form.
If "isText" is false, then the string "body" must contain a binary message in HEX form.

Example of usage

We define a JavaScript-operator that sends a message to WebSocket connection:

After running the test you can find the sent message in the log to check the work of this operator:

"Response" property

"Response" property of websocket object allows getting a server response. Example below shows how to get a response and parse it to JSON.

We define a JavaScript-operator which uses the "response" property to get the server response:

For the following server response:

The operator will write the following message to the log:

Next page