Kernel::Test::Role::IsTestCase::WebSocket

NAME

Kernel::Test::Role::IsTestCase::WebSocket – Role for WebSocket Endpoint Tests

ATTRIBUTES

has 'MojoApp'

Provides a Test::Mojo object.

has 'WebConfig'

Provides the "WebApp.conf" in Kernel used during the test.

By default it is empty.

Test can override this Attribute to set additional configuration values.

has 'WebSocketPath'

Provides the Web Socket URL

has 'Requests'

Provides the requests to be sent over the WebSocket Connection

has 'MessageMaxSize'

Provides the maximum allowed message size in bytes. The client will abort and disconnect beyond this size.

Setting this too low will produce a sudden text exit.

METHODS

requires BuildRequests()

The usage of the role requires a BuildRequests function which provides a list of requests with the following structure:

    return (
        {
            Name                    => 'Example test case name',
            PreTestStepFunction     => sub {},                    # optional, will receive $Self as first argument
                                                                  # and the Request structure as $Param{Request}
            PreTestStepFunction     => {                          # optional
                Name => 'FunctionName'
                Params => {},
            },
            TestStepFunction => sub {},                           # will receive $Self as first argument
                                                                  # and the Request structure as $Param{Request}
                                                                  # and the parsed Response structure as $Param{Response}
            PostTestStepFunction => sub {},                       # optional, will receive $Self as first argument
            PostTestStepFunction => {                             # optional
                Name => 'FunctionName'
                Params => {},
            },
            Data           => {},                                 # The data to be sent over the WebSocket Connection as JSON payload
            ExpectedResult => {},
        },
    );

Every test case should provide a Name and when possible a Data and ExpectedResult key. It's also possible to provide a function (PreTestStepFunction) which will be executed before the test case. You can directly define a function or a name from a function in the test file (and some params for the function). Same goes for PostTestStepFunction which can be used for a cleanup between the two test steps.

Run()

In a Web Socket test the run will be automatically executed for the defined test cases. It's possible to define a pre test case function which will be executed before a test case.

Scroll to Top