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 methods sendText and sendBinary and a property response. Below you can see how to use these methods in JavaScript-operators. The usage in JavaScript-functions is the same (for details you can also browse the topic "WAPT Pro Functions" in WAPT Pro Help contents).
"sendText" method
Using the sendText method you can send a text message to the certain WebSocket connection.
The syntax of sendText method:
websocket.sendText(string websocketConnectName, string body)
Here "websocketConnectName" is the name of WebSocket connection
and "body" is message body. Both parameters are strings.
The string "body" must contain a message in the text 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:
"sendBinary" method
Using the sendBinary method you can send a binary message to the certain WebSocket connection.
The syntax of sendBinary method:
websocket.sendBinary(string websocketConnectName, string body)
Here "websocketConnectName" is the name of WebSocket connection
and "body" is message body. Both parameters are strings.
The string "body" must contain a binary message in HEX form.
Example of usage
Let's take the same message body as for the sendText method, convert it to HEX form and
define a JavaScript-operator that sends a binary message to WebSocket connection:
After running the test we will find the same text message in the log:
"Response" property
"Response" property of websocket object allows getting a server response. You can use it in the body of JavaScript-functions only.