WebSocket Support

Document created by Chris Sommerstad Employee on Jul 20, 2017
Version 1Show Document
  • View in full screen mode

CloudTest provides full-fledged WebSocket protocol support,, including the ability to record WebSocket traffic via the Recording Editor or directly into the Clip Editor.

As part of this support, the following are provided (requires SOASTA 53 or later):

  • A new WebSocket target type
  • A new Event Group container
  • A new WebSocket Event Handler; All WebSocket event processing happens there, but other WebSocket processing (such as Send, Close, and Open) can occur elsewhere.
    • The WebSocket Event Handler includes six new WebSocket Event Containers that work together to handle WebSocket-related events:
      • Open
      • Close
      • Error
      • Idle
      • Message
      • Default
  • The new Web Socket actions include:
    • WebSocket Open
    • WebSocket Send
    • WebSocket Event Message
    • WebSocket Close
  • A new Wait action is also provided in this release. It is useful in WebSocket sessions, however, it can also be used in CloudTest test clips other than those based on a WebSocket target.

Event Group and Wait Clip Elements (Reference)

CloudTest's WebSocket support provides a WebSocket target and an Event Group container thatalso includes a target event handler (e.g. the WebSocket Event Handler, shown below).

Users will encounter the Event Group whenever a WebSocket is recorded. The Event Groups children include the new Event Handler, as well as the events that it supports, as well as the new actions that represent the asynchronous communication.

Note: In SOASTA 53, the Event Group is used for WebSocket targets only but is built for later support of other Targets that supports asynchronous events. Additionally, users should note that the Wait clip element is independent of the WebSocket feature and can be used in all forms of testing.

Event Group Container

An Event Group behaves similarly to a Group, except that at start it associates a Target Event Handler with some Target.

Target Event Handlers are “embedded only” in SOASTA 53. Therefore, you don’t “specify” a Target Event Handler at this time, one is automatically embedded for you.

The other items in the Event Group, aside from the Target Event Handler, are normal Clip Elements and will play just as in a Group container. Event handling occurs as long as the Event Group is playing. Once it ends, event handling ends, and the WebSocket connection is closed (if open).

The Event Group contains all WebSocket connection info. WebSocket clip elements are always found in an Event Group. The Clip Editor will alert the user of any attempt to add or move these clip elements to an unsupported location.

 

The Event Group can be put in sequenced or timed clips but not in a Page.

Wait Clip Element

This release includes a new Wait clip element that can be used with WebSocket tests, or any other kind of test. The Wait clip element is not expressly a part of the CloudTest WebSocket.

A Wait pauses current execution until some expression involving Custom Properties evaluates to true or the maximum wait time specified by the user is reached. This clip element is provided so that synchronization between processing in the Target Event Handler and other parts of the Clip may occur. Specify a maximum wait time.

WebSocket Clip Elements

This release introduces new WebSocket-related clip elements. There are two types:

  • Events that can occur in the WebSocket Event Handler
  • Actions that can occur in the Event Group.

WebSocket Event Handler - Events

The WebSocket Event Handler contains six new events. Open, Close, Error, Idle, Message, and Default (highlighted below).

WebSocket Actions

The Event Group actions include WebSocket Send, WebSocket Open, WebSocket Message, and WebSocket Close. While recording, these clip element types are detected automatically while doing HTTP recording to any site in which WebSocket is detected. Results can be filtered via these clip element types. Lower panel or inline editors are provided in the Clip Editor for operations such as extraction.

 

ObjectDescription

WebSocket Event Handler

Target Event Handlers can only contain the event containers, nothing else.

This event handler contains the user-defined logic for handling asynchronous events from the WebSocket target.

CloudTest doesn’t support “nested" Event Groups. An Event Handler may not contain an Event Group or a Target Event Handler.

The following WebSocket clip elements “events” can only be in the Target Event Handler. They cannot be in the Event Group itself:

WebSocket Open Event

This standard "on open" event fires when the WebSocket connection is opened.

WebSocket Close Event

This standard "on close" event fires when the WebSocket Connection is closed. The connection is closed automatically when the Event Group ends. The connection is opened when a new WebSocket Open clip element is executed. Close is valid only inside of an Event Group or Target Event Handler.

WebSocket Error Event  

This event fires if there is a WebSocket error.

WebSocket Idle Event  

This "on idle" event fires if there is no Web Socket activity for some amount of time.  The timeout length can be set through a System Property.

WebSocket Message Event

The message event fires when a WebSocket Message is received from the server and that message matches the message matching criteria for the event. The message event is like a Switch-Case statement and the Message Type Extraction provided under the WebSocket Event Handler is like a Switch statement.

WebSocket Default Event

The default event fires when a WebSocket Message is received from the server and that message does not match the message matching criteria for any Message Event.

WebSocket Send

The Send action.

WebSocket Message  

The WebSocket Message contains any validations and property sets that should
be done for the received message that caused the Message Event or Default Event to fire. Any validations and property sets are performed
when the Event Message Clip Element executes as part of the event
handling. The message can only repeat zero or one because it’s used for handling one event message received.

WebSocket Close

The close action.

WebSocket Event Handler Extraction Methods

The WebSocket Event Handler comes with two built-in extraction methods—one for Message and a second for Time Stamp as well as an Options section. In List View, these are shown inline.

However, the WebSocket Event Handler can also be edited in the Clip Editor lower panel.

In this lower panel, you will also find a Custom Properties panel. As shown above, this Event Handler already has a Custom Property (Target Event Handler Prop 1) with Constant and initial value set. The same Custom Properties that apply to all other clip elements also applies to each of the event containers and other clip elements found in the WebSocket Event Handler. As always, Custom Properties can be set and edited in the lower panel.

Message Type Extraction in WebSockets

Message Type Extraction is provided in order to extract a value from the received message that can then be used to match against the values in the message events in order to determine which message event should be fired to handle the received message. It is just like a Switch statement and a WebSocket Message Event container is like a Switch-Case statement.

For Message Type Extraction, click Using to select from among the drop-down options. The extraction methods provided for WebSocket Message are similar to existing options provided elsewhere for XPath, JSONPath, Regular Expression, and so forth.

For the method selected, enter an appropriate extraction expression or options, using the conventions of the method itself. For example, using RegEx with the value ^.*S will match everything in the message. Using the value ^.*S will result in a whole line match, such and will result in the message content being posted to the Events List.

Time Stamp Extraction in WebSockets

Time Stamp Extraction is provided in order to extract a time, if the server that sent the message inserted one, of the start of the processing for the message, so that we can compute the entire time to process this message, including time spent on the server that sent it.  Since we can’t know what the server is doing, the only way for us to get the total processing time is if the server sends us the start time as a timestamp.  In addition, this assumes that the server’s clock is synchronized to (or very close to) our clock.

For Time Stamp Extraction, click Using to select from among the drop-down options. The extraction methods provided for WebSocket time stamps are similar to existing options provided elsewhere for XPath, JSONPath, Regular Expression, and so forth.

For the method selected, enter an appropriate value to extract, using the conventions of the method itself. For example, using JSONPath with the value $.data.meta.timing.departure.

For time stamp, you must also provide the date/time stamp Pattern to use from among Millisecond since Epoch, Seconds since Epoch, or by a specified Pattern (an example of which you should supply).

Time Stamp Extraction can be specified at WebSocket Message Event container(s) and WebSocket Default Event container. Time Stamp Extraction specified at an Event Container will override the Time Stamp Extraction specified at the WebSocket Event Handler.

For the method selected, enter an appropriate value to extract, using the conventions of the method itself. For example, using JSONPath with the value $.data.meta.timing.departure.

For time stamp, you must also provide the date/time stamp Pattern to use from among Millisecond since Epoch, Seconds since Epoch, or by a specified Pattern (an example of which you should supply). Time Stamp Extraction can be specified at WebSocket Message Event container(s) and WebSocket Default Event container. Time Stamp Extraction specified at an Event Container will override the Time Stamp Extraction specified at the WebSocket Event Handler.

For example, setting Pattern and then enteingr this prescribed format, yyyy-MM-dd'T'HH:mm:ss.SSS'Z' (shown below) will result in placement of date formats matching this type into the Result Details, Events List.

TIP: For more about supported timestamp formats, see the Java documentation for SimpleDateFormat.

WebSocket Event Handler Options

The Event Handler options are failure actions to take (e.g. the same as those found elsewhere in CloudTest): Record only and Fail the parent.

Attachments

    Outcomes