Test Web sockets communication

Relevant for: API testing only

Open a Web socket connection

In order to test the communication between Web sockets, you must first open a connection to the Web socket. This step is mandatory for testing the sending/receiving of messages from a Web socket connection.

  1. In the Web Sockets section of the Toolbox pane, add a OpenSocket activity to the canvas.

  2. In the Input/Checkpoints tab in the Properties pane, in the Value cell for the URL property, enter the URL for the Web socket connection.

Back to top

Send a message to another Web socket

  1. In the Web Sockets section of the Toolbox pane, add a SendMessage activity to the canvas.

  2. In the Input/Checkpoints tab in the Properties pane, in the Value cell for the SocketID property, click the Link to a data source button . The Select Link Source dialog box opens.

  3. In the Select Link Source dialog box, select the Available steps option.

  4. In the list of available steps, select the OpenSocket activity. A list of available properties is displayed in the right pane.

  5. In the right pane, select the General tab .

  6. In the General tab, select the SocketID property and click OK to link the ReceiveMessage step to the OpenSocket step.

  7. In the Properties pane, select the HTTP tab .

  8. In the HTTP tab, in the Request Body section, from the drop-down list, select the format for your message body. You can send a message with Text, XML, or JSON.

  9. In the Request Body section, in the Text Editor area, enter the body of your message to send.

    Note: You can load the XML or JSON for the sent message body from an external file by click the Load button in the text editor area.

  10. In the Toolbox pane, expand the Flow Control activities section.

  11. From the Flow Control activities, drag a Wait activity to the canvas. The Input/Checkpoints tab opens in the Properties pane.

  12. In the Input/Checkpoints tab, in the Value cell for the Completion event property, click the Link to a data source button . The Select Link Source dialog box opens.

  13. In the Select Link Source dialog box, select the Available steps option. A list of available steps is displayed in the Select a step: (left) pane.

  14. In the Select a step: pane, select the ReceiveMessage activity. A list of available properties is displayed in the Select a property: (right) pane.

  15. In the Select a property pane, select the General tab .

  16. In the General tab, select the Completion event name property and click OK. UFT links the ReceiveMessage step to the Wait step, instructing the test to wait to proceed until the message is received from the Web socket in the ReceiveMessage step.

Back to top

Receive a message from another Web socket

  1. Prerequisite: Create an OpenSocket step in your test.

  2. In the Web Sockets section of the Toolbox pane, add a ReceiveMessage activity to the canvas.

  3. In the Input/Checkpoints tab in the Properties pane, in the Value cell for the SocketID property, click the Link to a data source button . The Select Link Source dialog box opens.

  4. In the Select Link Source dialog box, select the Available steps option.

  5. In the list of available steps, select the OpenSocket activity. A list of available properties is displayed in the right pane.

  6. In the right pane, select the General tab .

  7. In the General tab, select the SocketID property and click OK to link the SendMessage step to the OpenSocket step.

  8. In the Properties pane, select the HTTP tab .

  9. In the HTTP tab, in the Received Message Body section, from the drop-down list, select the format for your message text. You can receive a message body with Text, XML, or JSON.

  10. In the Received Message Body section, in the Text Editor area or the regular expression grid area, enter the body of the expected message or a regular expression representing the recieved message body.

    Note: You can load the XML or JSON for the received message body from an external file by click the Load button in the text editor area.

  11. Back to top

Close the Web socket connection

Note: This step is optional. You should use this step if you want to send or receive messages from a different Web socket in later test steps.

  1. Prerequisite: Create an OpenSocket step in your test.

  2. In the Web Sockets section of the Toolbox pane, add a OpenSocket activity to the canvas.

  3. In the Input/Checkpoints tab in the Properties pane, in the Value cell for the SocketID property, click the Link to a data source button . The Select Link Source dialog box opens.

  4. In the Select Link Source dialog box, select the Available steps option.

  5. In the list of available steps, select the OpenSocket activity. A list of available properties is displayed in the right pane.

  6. In the right pane, select the General tab .

  7. In the General tab, select the SocketID property and click OK to link the CloseSocket step to the OpenSocket step.

  8. (Optional)- In the Checkpoints section of the Input/Checkpoints tab, select the Validate checkbox in the Result row to set a checkpoint to check if the Close operation succeeds.

Back to top