Cypress
This article walks you through setting up the Perfecto-Cypress integration. Cypress is a growing web front-end testing solution. Perfecto customers can utilize the Perfecto-Cypress SDK, which provides the following functionality:
- Running Cypress tests in the cloud in parallel and at scale
- Running Cypress tests from a cloud and a secured repository from the command-line of a continuous integration (CI) tool, such as Jenkins
- Enhanced quality visibility, tagging, and debugging
maxNumOfDevices
capability to prevent more Mac machines from being requested than are available, a situation that would result in an error and blocked tests.
Key benefits of Perfecto with Cypress include:
- Fast and scalable execution in the cloud: more OS versions, parallel test execution, and same-day support for new browser versions
- Full integration with CI/CD: executable from CI and the command line
- Seamless installation and full compliance with Cypress open-source
- Secure execution in the cloud
- Advanced reporting and analysis
- Unified solution for Selenium, WebDriverIO, and other frameworks as well as Cypress testing
To learn even more about Cypress, consider taking our BlazeMeter University course. Guided by Cypress guru Gleb Bahmutov, you will learn how to use Cypress 10 to do end-to-end testing for your web apps.
On this page:
Support info
Perfecto’s Cypress SDK is fully compliant with the Cypress technology. It supports the following operating systems and browsers:
- Windows: Google Chrome, Mozilla Firefox, Microsoft Edge
- Mac: Google Chrome, Mozilla Firefox
In addition, Perfecto supports Cypress projects with access to private libraries using the .npmrc
file of the NPM package manager. This feature requires the latest version of the Perfecto-Cypress SDK.
Cypress versions 10.11.0, 11.2.0, 12.17.2, and 13.1.0 are cached. All other versions are supported. For performance reasons, consider specifying one of the cached Cypress versions in your configuration. Otherwise, the execution takes an additional 4 minutes.
For more support information, see Supported platforms > Test frameworks > Cypress.
If you want to start working with Cypress 10, see Migrate to Cypress version 10 or later.
Prerequisites
The integration requires that the following be installed:
-
Important: Make sure that you choose a NodeJS version supported by your requested Cypress version. For more information, see the Cypress Changelog.
- The IDE of your choice
Network prerequisites
If you connect via VPN, for smooth Cypress execution, make sure the following URLs are accessible from your network:
-
<your-cloud>.app.perfectomobile.com
-
<your-cloud>.perfectomobile.com/lab-execution/
-
Access to the npm registry or any other custom registry you use
If these URLs are not accessible, Cypress execution may be limited in that executions will run, but Cypress will not run and no tests will be executed or shown in the SDK.
Project prerequisites
When working with Perfecto Connect, the uploaded project, including any 3rd-party package used, should be able to work behind a proxy without any issue.
An example of a problematic 3rd-party package would be one that makes use of axios, which currently has a problem working behind a proxy. Therefore, projects using such a package cannot work with Perfecto Connect.
SDK proxy configuration
If you need to work behind a proxy when using the Perfecto-Cypress SDK, you need to configure the following environment variable on your workstation: HTTPS_PROXY
For a proxy without authentications, set the following:
HTTPS_PROXY=http://<proxy ip>:<proxy port>
For proxy with authentications, set the following:
HTTPS_PROXY=http://<username>:<password>@<proxy ip>:<proxy port>
Step-by-step instructions
This section provides detailed setup instructions. To summarize: You install Cypress, the Perfecto-Cypress SDK, and the SDK configuration files in the same folder and in this exact order. The installation folder is a new folder that you create inside your IDE's Cypress workspace folder. This folder is also referred to as the Cypress test folder.
If you need to run scripts on a virtual machine (VM) before and after running a Cypress test, see Run scripts on a VM before or after a test.
- Launch a terminal in your IDE.
- In the workspace folder, create a new folder, for example CypressSEDemo (as shown in the images included in this article). This is the folder we refer to as tests root folder.
- Change to the new folder you created.
-
Run the following command to create the
package.json
file:Copynpm init
-
In the generated
package.json
file, specify the name of the package, version, and Cypress version, as follows:Copy{
"name": "<NAME>",
"version": "<VERSION>",
"dependencies": {
"cypress": "^<CYPRESS_VERSION>",
"perfecto-cypress-sdk": "^0.0.52",
"perfecto-cypress-reporter": "^0.0.12"
}
}Where:
-
<NAME>
and<VERSION>
can be anything you like. -
<CYPRESS_VERSION> can be any version, but consider using one of the cached versions to get better performance (see also Support info).
-
-
To install Cypress, run the following command from the command line:
Copynpm install cypress --save-dev
--save-dev
saves it as a dependency in thepackage.json
file. -
To launch Cypress, run the following command:
Copynpx cypress open
This launches the Cypress UI and also creates a
cypress
folder inside the CypressSEDemo folder you created in step 1, including thecypress.json
file. - In the Cypress UI:
- Click any
*.spec.js
file and launch it in the selected browser. - Close the Cypress UI.
- Click any
-
Install the Perfecto-Cypress SDK by running the following command (make sure your location is inside the tests root folder, which includes the
cypress
folder):Copynpm install perfecto-cypress-sdk --save-dev
-
To add Perfecto Cypress Reporter capabilities, run the following command:
Copynpm install perfecto-cypress-reporter --save-dev
Running Cypress tests in Perfecto requires the following configuration files:
perfecto-config.json
: See Perfectoconfig options.cypress.json
: See the Cypress documentation.package.json
: All dependencies that your project needs to execute theCypress run
command.
init
command, you need the path to the Cypress tests folder.
To initialize the SDK:
-
Run the
init
command to generateperfecto-config.json
(see also Perfecto-config.json details) (make sure your location is inside the tests root folder, which includes thecypress
folder)::Copynpx perfecto-cypress init --tests.path=./ --skip
where
--skip
omits the interactive questions that otherwise occur (about the cloud name, security token, and so on). - In the
perfecto-config.json
file, define the following:- The cloud name, for example
demo
. The SDK automatically adds.perfectomobile.com
. - The security token, either hard-coded or passed later as a parameter in the command line.
- The test specs you want to execute in the cloud, for example
**/*.specs.js
for thespecsExt
parameter
- The cloud name, for example
-
Depending on your Cypress version:
-
Version 10:
Import perfecto-cypress-reporter into the support file
cypress/support/e2e.js
by adding the following code. -
Version 9 and earlier:
Import perfecto-cypress-reporter into the support file
cypress/support/index.js
by adding the following code.
Copyimport 'perfecto-cypress-reporter' // or require('perfecto-cypress-reporter');
-
-
Use the following SDK commands as needed:
run
,pack
,upload
For more information on these commands, run the
--help
command.CopyHelp
npx perfecto-cypress --help
perfecto-cypress <command>Commands:
perfecto-cypress init init Perfecto and Cypress configuration files
perfecto-cypress pack Zip tests files according to configurations
perfecto-cypress run Run Cypress tests on Perfecto cloud
perfecto-cypress upload Upload tests zip archive to Perfecto cloud repository
Options:
--version Show version number [boolean]
--help Show help [boolean]
Alternative upload option
As an alternative to the SDK, you can upload your project through the Perfecto UI. To do this, perform the following steps:
-
Pack your project, as follows:
-
Go to your project folder.
-
Open a command line window.
-
Run the following command to create a zip file of your project:
Copynpx perfecto-cypress pack
-
-
Upload your compressed project to the Perfecto repository using the Perfecto UI (see also Manage the repository):
-
In a browser, navigate to the URL of your Perfecto cloud.
-
On the landing page, under Assets and Setup, click ACCOUNT SETUP.
-
In the Repository view, click the upload icon at the bottom right:
-
Browse to the zip file you want to upload.
-
In the File upload dialog box, make sure that the name of the zip file is unique, select Private or Public, and click UPLOAD.
-
-
-
From your project's root folder (where
perfecto-config.json
is located), run your project with thetests.artifactKey
parameter, as follows:Copynpx perfecto-cypress run --tests.artifactKey=<PRIVATE/PUBLIC>:<zip file name>
For a quick execution, perform the following steps:
-
Run the command from terminal, as follows:
Copynpx perfecto-cypress run --config=.\CypressSEDemo\perfecto-config.json
where
CypressSEDemo
is the name of the folder you created in step Launch a terminal in your IDE.. -
Launch Perfecto and go to Test Analysis > Live Stream to view the live execution.
When it is done, you can see the results based on the CI Job or Project, or you can open the report link that should appear in the command line window.
Tip: The test report also provides an option for downloading the Cypress logs. In the report, at the top right, click the download button and select Cypress logs.
Following is a complete list of command line parameters, including the known reporting perfecto-cypress-sdk
options to be passed.
Run command options
npx perfecto-cypress run --help
perfecto-cypress run
Run Cypress tests on Perfecto cloud
Credentials options (will override config file)
--credentials.cloud, --cloud Cloud name [string]
--credentials.securityToken, --token Offline token [string]
Test options (will override config file)
--tests.artifactKey, --ta Repository artifact key [string]
--tests.path, --tp Root path for test to pack [string]
--tests.ignore, --ti ignore files list [array]
--tests.specsExt, --ts specs files extension
[string] [default: "*.spec.js"]
Reporting options (will override config file)
../Perfecto/test-analysis/download_the_reporting_sdk.htm
--reporting.jobName, --rjn reporting job name [string]
--reporting.jobNumber, --rjNum reporting job number [number]
--reporting.branch, --rb reporting branch [string]
--reporting.projectName, --rpn reporting project name [string]
--reporting.projectVersion, --rpv reporting project version [string]
--reporting.author, --ra reporting author [string]
--reporting.tags, --rt reporting tags, example: tag1 tag2 [array]
--reporting.customFields, --rcf reporting custom fields, example:
key1,value1 key2,value2 [array]
Options:
--env, -e environment variables to attach to `cypress run` command
--config, -c Path to config file, see documentation:
[default: "./perfecto-config.json"]
securityToken
as a parameter instead of storing it in the perfecto-config.json
file.
When uploading a Cypress test suite to the Perfecto cloud, utilize the following command options:
Upload command options
npx perfecto-cypress upload --help
perfecto-cypress upload
Upload tests zip archive to Perfecto cloud repository
Credentials options (will override config file)
--credentials.cloud, --cloud Cloud name [string]
--credentials.securityToken, --token Offline token [string]
Options:
--archivePath, -p Path to tests zip file [default: "./perfecto-cypress.zip"]
--temporary, -t Upload tests archive as temp artifact
[boolean] [default: true]
--folderType, -f Set the location of tests archive in the repository
[choices: "PRIVATE", "PUBLIC", "GROUP"] [default: "PRIVATE"]
--config, -c Path to config file, see documentation:
[default: "./perfecto-config.json"]
After uploading a .zip
file to the cloud, the cloud admin should obtain the repository ID of that .zip
file and pass it through the run
command to be executed in the cloud. For example, if the repository ID is PRIVATE:perfecto-cypress.zip
, the command would be as follows:
npx perfecto-cypress run --config=.\test\perfecto-config.json --ta=PRIVATE:perfecto-cypress.zip
Perfecto-config.json details
Option |
Example |
Description |
Required |
---|---|---|---|
credentials |
{ |
Specifies the credentials used to initiate the communication with Perfecto services. |
Can also be provided as a CLI parameter. |
capabilities |
[ { "deviceType": "Web", |
Specifies the required capabilities. For more information about available capabilities, see Define capabilities. For each configuration, you also need to add the Perfecto Connect tunnelId value. Copy
Example
For more information, see Associate a device with a Perfecto Connect tunnel. Parallel executionThe If Note that not specifying this capability can affect the number of available licenses, thus limiting other web executions, such as Selenium. Therefore, as a best practice, consider starting with a value of
|
Required |
tests.path |
"./tests"
|
Specifies the path to the
This is also the folder that the SDK packs and uploads to the Perfecto cloud.
|
Can be provided also as a CLI parameter. |
tests.ignore |
[ |
Specifies a list of patterns to exclude from the tests' zip archive. |
Optional |
tests.specsExt |
"**/*.cy.js"
|
Specifies a pattern to guide the SDK which test specs to run. |
Can be provided also as a CLI parameter |
nodeVersion |
"18"
|
Specifies the major Node.js version for the Cypress execution environment. Supported values:
For comprehensive support information, see Supported platforms. |
Optional |
framework |
"CYPRESS"
|
|
Required |
env |
{ |
Specifies the environment variables that your Cypress tests need. |
Optional |
reporting |
{ |
Specifies information for Perfecto Smart Reporting. For more information, see Smart Reporting capabilities. |
Optional |
scriptName
|
"My Cypress project" |
The name used as the Report Name for the Report Library and Live Stream interfaces. See also Smart Reporting capabilities. |
Optional |
Best practices
This section lists best practices, recommendations, and clarifications that will help you avoid common pitfalls.
-
supportFile: This option is part of the
cypress.json
file. Make sure it is set totrue
for Cypress reports to be included in Perfecto Smart Reporting. If you remove it from the file, it is enabled by default. However, if you set it tofalse
, the Cypress tests will not appear in Perfecto Smart Reporting. -
Project hierarchy: Use the sample project as a template. You can clone it and start from there.
A few words on the most important locations and relationships:
-
Tests are usually located in the
Cypress/Integration
folder. -
The
cypress.json
andpackage.json
files need to be located in the project's root folder. -
The
perfecto-config.json
file can be located anywhere in the project or even outside of the project, but thetests.path
option must provide a valid path to the folder where the Cypress test files reside, along withcypress.json
andpackage.json
.
-
-
Latest version: Make sure to always work with the latest version of
perfecto-cypress-reporter
andperfecto-cypress-sdk
.