1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- @exampleServer=localhost:9500
- ###
- ### Simple WebSocket Request
- WEBSOCKET ws:
- ### Request with client messages
- WEBSOCKET ws:
- Content-Type: application/json
- {
- "message": "Hello, server!",
- "repeat": 3
- }
- ### Requests with scripts
- WEBSOCKET ws:
- Content-Type: application/json
- {
- "message": "Beginning message"
- }
- > {%
- var i = 0
- response.body.onEachMessage((message, unsubscribe, output) => {
- i++
- debugger
- const jsonMessage = JSON.parse(message);
- client.test("Server sent a JSON with 'message' property: " + i, () => {
- client.assert(jsonMessage.message !== undefined)
- });
- if (jsonMessage.message.includes("finish")) {
- unsubscribe()
- return
- }
- if (i === 5) {
- output(JSON.stringify({
- message: "finish"
- }));
- } else {
- output(JSON.stringify({
- message: "Message from the script: " + i
- }));
- }
- }, () => {
- client.log("We stopped listening for WebSocket from the current 'onEachMessage' call!")
- });
- %}
|