The Web Sockets handler provides steps which allow Chorus to open a web socket to listen for connections for client processes wishing to publish step definitions. The chorus-js library provides a way for an app running in a browser to connect to the web socket and publish steps.
Typically test scenario will open a web socket and then start a browser (using Selenium Handler). The browser will then be navigated
to a URL which loads a web app which we want to test. The test scenario will then wait for the web app to be loaded and the browser to make a connection.
The web app will use the chorus-js javascript library to open a web socket connection to the Chrous interpreter and will publish its step definitions. Once the step definitions have been received, the interpreter will then proceed with the test and may invoke steps within the browser-based app by invoking them over the web socket connection.
You can use this by adding ‘Uses: Web Sockets’ to the top of your feature file:
Uses: Web Sockets
Uses: Web Sockets
Uses: Selenium
Feature-Start:
Given I start a web socket server
And I open the RemoteWebDriver browser
And I navigate to http://mywebapp-url
And I wait for the web socket client myWebAppPublisher
Scenario: I can use steps exported from myWebAppPublisher
When I enter a user name
And I enter a password
Then I can log in to the myWebAppPublisher app
You will need to ensure the chorus-websockets extension is on your classpath if using the JUnit Suite Runner, e.g. for a Maven project:
<dependency>
<groupId>org.chorusbdd</groupId>
<artifactId>chorus-websockets</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
At present chorus only supports opening a single web socket server during each test feature This has the name ‘default’ You can configure the port for the ‘default’ web socket in the feature properties:
# chorus.properties:
websockets.default.port=9099
If left unspecified, the port will default to 9080
See Handler Configuration for more details on configuring handlers
The web socket will be automatically closed at the end of the test feature (if FEATURE scope is used) or at the end of each scenario (if SCENARIO scope is used). Scope will default to SCENARIO unless the web socket is created in the special Feature-Start: scenario, in which case it will default to FEATURE
See Chorus JS
Step | Example | Deprecated | Description | Retry Duration (wait for step to pass) |
---|---|---|---|---|
.*start (?:a|the) web socket server | Given I start a web socket server | No | Start a web socket server. The listening port will be 9080 if not specified in properties. | |
.*stop (?:a|the) web socket server | Then I stop the web socket server | No | Stop a web socket server. | |
.*wait for (?:the )web socket clients? ([a-zA-Z0-9-_, ]+) | And I wait for the web socket client singlePageApp | No | Wait for one or more named web socket clients to connect to the web socket. If more than one name is specified the list is comma delimited | |
.*(?:the )?web socket clients? ([a-zA-Z0-9-_, ]+) (?:is|are) connected | Then the web socket clients singlePageApp1, singlePageApp2 are connected | No | Check that the named web socket clients are connected. If more than one name is specified the list is comma delimited | |
.*show all the steps published by connected web socket clients | THen I show all the steps published by connected web socket clients | No | Show the steps published by all connected web socket clients in Chorus' interpreter's output | |
Web Sockets start | #! Web Sockets start | No | Directive to start a web socket server. The listening port will be 9080 if not specified in properties. | |
Web Sockets stop | #! Web Sockets stop | No | Directive to stop a web socket server. |
Property | Is Mandatory | Description | Default | Validation |
---|---|---|---|---|
port | yes | Which local port the web socket server should listen on | 9080 | \d+ |
stepTimeoutSeconds | yes | How long the Chorus interpreter should wait for a result after executing a step on a web socket client before failing the step | 60 | \d+ |
clientConnectTimeoutSeconds | yes | How long the Chorus interpreter should wait to receive a connection from a client before failing the connection step | 60 | \d+ |
scope | yes | Whether the web socket should be closed at the end of each scenario, or at the end of the feature | SCENARIO | One of: SCENARIO, FEATURE |