forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket.feature
49 lines (43 loc) · 1.83 KB
/
websocket.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@ignore
Feature: websocket testing
Scenario: only listening to websocket messages
* def handler = function(msg){ return msg.startsWith('{') }
* def socket = karate.webSocket(demoBaseUrl + '/websocket', handler)
# first we post to the /websocket-controller end-point which will broadcast a message
# to any websocket clients that are connected - but after a delay of 1 second
Given url demoBaseUrl
And path 'websocket-controller'
And request { text: 'Rudy' }
When method post
Then status 200
And def id = response.id
# this line will wait until the handler returns true
* listen 5000
* json result = listenResult
* match result == { id: '#(id)', content: 'hello Rudy !' }
Scenario: using the websocket instance to send as well as receive messages
* def handler = function(msg){ return msg.startsWith('hello') }
* def socket = karate.webSocket(demoBaseUrl + '/websocket', handler)
* socket.send('Billie')
* listen 5000
* match listenResult == 'hello Billie !'
Scenario: listen for multiple websocket messages
* def handler = function(msg){ return msg.startsWith('hello') }
* def socket = karate.webSocket(demoBaseUrl + '/websocket', handler)
* socket.send('Billie')
* listen 5000
* match listenResult == 'hello Billie !'
* socket.send('Bob')
* listen 5000
* match listenResult == 'hello Bob !'
Scenario: change the websocket handler for messages
* def handler = function(msg){ return msg.contains('Billie') }
* def socket = karate.webSocket(demoBaseUrl + '/websocket', handler)
* socket.send('Billie')
* listen 5000
* match listenResult == 'hello Billie !'
* def handler = function(msg){ return msg.contains('Bob') }
* socket.setTextHandler(handler)
* socket.send('Bob')
* listen 5000
* match listenResult == 'hello Bob !'