Cypress
Cypress is a front-end testing tool for web applications using modern JavaScript frameworks.
Cypress enables you to write these types of tests:
- End-to-end tests
- Integration tests
- Unit tests
It can test anything that runs on a browser.
Requirements
Cypress Support is available only in SaaS clouds.
In order to run Cypress projects in Cloud, you need to have a Docker Swarm and Execution Service set up in your environment.
Cypress projects are run inside containers in Docker Swarm using the Execution Service API.
In order to run Cypress project Cloud, you need to have Browser license.
Execution Service API
The role of the user performing the Rest Operation is specified by the Authorization header. For a detailed example see How To Execute Rest API.
Start a Cypress Execution
This enables users to run Cypress projects.
Cypress projects are run asynchronously. The response received is immediate.
Our Cypress support includes version 10.
POST /api/v1/executions
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | String | Yes | Specify execution type. For Cypress use Cypress. |
project | File | Yes | The Cypress project to run. Compress the entire Cypress project and select the .zip file. A valid project contains a cypress.json file in the root directory. |
conf | JSON String | No | A configuration file for the requested execution. Please read the next section for more information about the configuration. |
POST Cypress Execution Response Expand source
{
"status": "SUCCESS",
"data": {
"Test Run Id": "3520546",
"Link to Reporter": "https://CLOUD_SERVER/reporter/#/test-view-view/-1?testView={%22byKey%22:%22test.run.id%22,%22byKeyValue%22:%223520546%22}"
},
"code": "OK"
}
Cypress Configuration
In order to run Cypress project, a configuration must be supplied.
There are 2 options to add configuration:
- Add the conf parameter as a JSON string to the POST request.
- Create a file named digitalai.json with the required configuration in the root directory of the project.
If both options are used, the file is ignored.
Configuration Parameters:
Name | Type | Mandatory | Description |
---|---|---|---|
browsers | List | Yes | A list of browser names and cypress versions to run the project on. Each entry in the list is as follows:{ "browser": "browser name" "imageVersion": "cypress image version" } Supported browsers are Chrome, Firefox and Electron. |
runTags | Map | No | A map of tags and their values to add to the report of each test in the project. For example: { "tag 1": "tag 1 value" "tag 2": "tag 2 value" } |
exclude | List | No | A list of test names to exclude from the project while running. For example:"exclude": [ "actions.spec.js", "badTest.spec.js" ] |
npm_dependencies | List | No | A list of npm dependencies that need to be installed before running the project. For example:"npm_dependencies": [ "npm-package1", "npm-package2", ... ] |
runConfFile | String | No | A configuration file to run the project with. This file must be located in the root directory. "myConfigFile.json" |
Cypress configuration example Expand source
{
"browsers": [{
"browser": "chrome",
"imageVersion": "8.3.0"
},
{
"browser": "chrome",
"imageVersion": "8.2.0"
},
{
"browser": "firefox",
"imageVersion": "8.2.0"
},
{
"browser": "electron",
"imageVersion": "8.1.0"
}
],
"runTags": {
"tag 1" : "tag 1 value",
"tag 2" : "tag 2 value",
"tag 3" : "tag 3 value"
},
"exclude": [
"actions.spec.js",
"badTest.spec.js"
],
"npm_dependencies": [
"npm-package1",
"npm-package2"
],
"runConfFile": "myConfigFile.json"
}
Get Cypress Execution Status
This obtains the Cypress execution status based on execution ID.
The ability to obtain an execution status depends on the user type.
- A user can get only his own session status.
- A project admin can get his own session status and the statuses from other users of his project.
- An admin can get any session status on his cloud.
GET /api/v1/executions/<Execution_ID>/status
Get Cypress Execution Response Expand source
{
"code": "OK",
"data": {
"Test Run Id": "3023f8be-783e-4b70-b830-3ca2e4bd3f7a",
"Test Run State": "RUNNING",
"Number of requested browsers": "2",
"Number of browsers completed": "0",
"Number of browsers running": "2",
"Number of browsers in queue": "0",
"Link to Reporter": "https://CLOUD_SERVER/reporter/reporter/dashboard/#/test-view-view/-1?testView=%7B%22byKey%22:%22test.run.id%22,%22byKeyValue%22:%223023f8be-783e-4b70-b830-3ca2e4bd3f7a%22%7D"
},
"status": "SUCCESS"
}
Cancel Cypress Execution
This cancels a Cypress execution project by execution ID.
The ability to cancel an execution depends on the user type.
- A user can cancel only his own execution.
- A project admin can cancel his own execution executions from other users of his project.
- An admin can cancel any execution on his cloud.
PUT /api/v1/executions/<executionId>/actions/cancel
Response if session canceled successfully Expand source
Execution session id - <session id> canceled
Response if user has no privileges to cancel the session Expand source
{
"status": "ERROR",
"data": {
"User": "Security Error"
},
"code": "FORBIDDEN"
}
Get Cypress Execution Logs
This gets the logs of a certain Cypress run.
The ability to obtain the logs of a run depends on the user type.
- A user can get only his own session logs.
- A project admin can get his own session logs and from other users of his project.
- An admin can get any session logs on his cloud.
GET /api/v1/executions/<Execution_ID>/logs
The response is a zip file with the logs or an error message if any error occurred.