Websockets
Required config
To test a websocket API you need to add the <websockets> config block to the integrations.xml file located in the config folder.
<integrations> <websockets> <api alias="myAlias" url="wss://websocket.url" protocol="stomp" enabled="true"/> <api alias="example" url="ws://example" protocol="standard" enabled="false"/> </websockets> ...</integrations>This configuration requires the following parameters:
1. alias - alias for this config to be used in test scenarios (must be unique)
2. URL - URL of your resource to connect to
3. protocol - specifies the WebSocket protocol of this API (can be "standard" or "stomp")
4. enabled - flag to enable/disable this config (can be "true" or "false")
Testing the Standard websocket API:
To interact with a websocket you need to set: the main (parent) command in which all commands are executed, the disconnect argument which specifies whether to disconnect the connection after closing the main tag (default disconnect="true"), the alias argument which is the same as in websocket integration config.
Inside main command <websocket>...</websocket> command you can use commands:
<receive comment="Your comment" maxRecords="1" timeoutMillis="3000"> <message>[{ "some": "payload" }]</message> </receive>Receive command is used to checking the receipt of messages from the server. The command has arguments:
comment - whichused to comment your command
maxRecords- limiter of messages you want to compare
timeoutMillis- the maximum time to wait before receiving a message, specified in milliseconds
<message>[]</message>- message that you will get from server or File where will be message that you will get from server<file>expected_25.json</file>
<send comment="Your comment"> <message>{ "some": "payload" }</message></send>Send command you use to send message to server. The command has arguments:
comment- which is used to comment your command
<message></message>- message that you will send to server or File where will send message what you will get from server expected_35.json
Sample script for testing websockets:
<websocket comment="Your comment" alias="myAlias" disconnect="true"> ... <receive comment="Receive message" maxRecords="0"> <message>[]</message> </receive> <send comment="Send subscribe"> <message> { "event": "subscribe", "subscription": { "name": "value"} } </message> </send> ...</websocket>Testing the websocket API with Stomp protocol:
To interact with a websocket - The main (parent) command in which all commands are executed, The disconnect argument specifies whether to disconnect the connection after closing the main tag (default disconnect="true") The alias argument is the same as in websocket integration config.
If the resource you want to test uses the Stomp protocol, all commands inside the <websocket>...</websocket> command must be placed in the <stomp>...</stomp> subcommand, after it you can use the following commands:
<subscribe comment="Subscribe to topic" topic="/topic/server"/>Subscribe is used to subscribe to a specific topic from which you want to receive messages. The command has arguments:
comment- which used to comment your command
topic- here you specify the topic from which you want to receive messages
<receive comment="Receive 'ping response' message" topic="/topic/ping" maxRecords="1" timeoutMillis="100"> <message>[{"value" : "ping message"}]</message></receive>Receive command is used to check the receipt of messages from the server. The command has arguments:
comment- is used to comment your command
topic- here you specify the topic from which you want to receive messages
count - indicatesthe number of first messages that you want to compare
timeoutMillis- the maximum time to wait before receiving a message, specified in milliseconds
<message>[]</message>- message that you will get from server or File where will be message that you will get from server<file>expected_28.json</file>
<send comment="Send 'ping' message" endpoint="/app/ping"> <message>ping message</message></send>Send command you use to send message to server. The command has arguments:
comment- is used to comment your command
endpoint- here you specify the endpoint where you want to send messages
<message>[]</message>- message that you will send to server or File where will send massage what you will get from server expected_35.json
Sample script for testing websockets of the resource that use stomp protocol:
<websocket comment="Connect to stomp websocket api" alias="TESTER" disconnect="false"> <stomp> <subscribe comment="Subscribe to topic" topic="/topic/server"/> <receive comment="Receive 'server periodic' messages" topic="/topic/server" maxRecords="3"> <file>expected_3.json</file> </receive> <send comment="Send 'ping' message" endpoint="/app/ping"> <message>ping message</message> </send> </stomp></websocket>