Skip to main content

Run Playwright Automation Tests on HyperExecute Using Cypress v9


HyperExecute is a smart test orchestration platform to run end-to-end Puppeteer tests at the fastest speed possible. HyperExecute lets you achieve an accelerated time to market by providing a test infrastructure that offers optimal speed, test orchestration, and detailed execution logs.

The overall experience helps teams test code and fix issues at a much faster pace. HyperExecute is configured using a YAML file. Instead of moving the Hub close to you, HyperExecute brings the test scripts close to the Hub! This guide will cover the basics of getting started with Cypress v9 testing on the Lambdatest HyperExecute grid.

HyperExecute has several state of the art features to help you optmize your testing process. Go through the features page to take a look at all the tools that HyperExecute offers.

HyperExecute is compliant with leading security standards - SOC2, GDPR, and CCPA. Refer to HyperExecute Getting Started Guide for more information about features offered by HyperExecute.

All the code samples in this documentation can be found in the Cypress v9 HyperExecute GitHub repository. You can either download or clone the repository to run tests on the HyperExecute Grid.

Gitpod


Follow the below steps to run Gitpod button:

  1. Click the Open in Gitpod button (You will be redirected to Login/Signup page).Gitpod popup
  2. Login with Lambdatest credentials. You will be redirected to HyperExecute dashboard with pop-up confirming to 'Proceed' to Gitpod editor in the new tab and current tab will show hyperexecute dashboard. Run in Gitpod

Prerequisites for Running Cypress v9 Tests On The HyperExecute Grid


  • Download the HyperExecute CLI:

    The HyperExecute CLI is used for interacting with, and running the tests on the HyperExecute Grid. It provides a host of other useful features that accelerate test execution. You need to download the HyperExecute CLI binary corresponding to the platform (or OS) from where the tests are triggered. Shown below is the HyperExecute CLI download location for different platforms:
PlatformHyperExecute CLI download location
Windowshttps://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe
macOShttps://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute
Linuxhttps://downloads.lambdatest.com/hyperexecute/linux/hyperexecute

For detailed information about HyperExecute CLI, please refer to HyperExecute CLI section in the HyperExecute getting started guide.

  • Configure Environment Variables:

    Before the tests are run, please set the environment variables LT_USERNAME & LT_ACCESS_KEY from the terminal. The account details are available on your LambdaTest Profile page. For macOS:
export LT_USERNAME=LT_USERNAME
export LT_ACCESS_KEY=LT_ACCESS_KEY

For Linux:

export LT_USERNAME=LT_USERNAME
export LT_ACCESS_KEY=LT_ACCESS_KEY

For Windows:

set LT_USERNAME=LT_USERNAME
set LT_ACCESS_KEY=LT_ACCESS_KEY

Auto-Split Execution with Cypress v9

Auto-split execution mechanism lets you run tests at predefined concurrency and distribute the tests over the available infrastructure. Concurrency can be achieved at different levels - file, module, test suite, test, scenario, etc.

For more information about auto-split execution, check out the Auto-Split Getting Started Guide

Core

Auto-split YAML file (yaml/.hyperexecute_autosplit.yaml) in the repo contains the following configuration:

globalTimeout: 90
testSuiteTimeout: 90
testSuiteStep: 90

Global timeout, testSuite timeout, and testSuite timeout are set to 90 minutes.

The runson key determines the platform (or operating system) on which the tests are executed. Here we have set the target OS as Windows.

runson: win

Auto-split is set to true in the YAML file.

 autosplit: true

retryOnFailure is set to true, instructing HyperExecute to retry failed command(s). The retry operation is carried out till the number of retries mentioned in maxRetries are exhausted or the command execution results in a Pass. In addition, the concurrency (i.e. number of parallel sessions) is set to 2.

retryOnFailure: true
maxRetries: 1
concurrency: 2

Cypress is set to true in the YML file.

cypress: true

Cypress Build name and tags are added in the YML file.

cypressOps:
Build: "Hyperexecute Cypress Sample Build"
Tags: ["Hyperexecute","Cypress", "Windows", "Autosplit", "V9"]
BuildTags: ["Hyperexecute-Cypress"]

Pre Steps

Steps (or commands) that must run before the test execution are listed in the pre run step.

pre:
- npm install

Post Steps

Steps (or commands) that need to run after the test execution are listed in the post step. In the example, we cat the contents of yaml/.hyperexecute_autosplit.yaml

post:
- cat yaml/.hyperexecute_autosplit.yaml

The testDiscovery directive contains the command that gives details of the mode of execution, along with detailing the command that is used for test execution. Here, we are fetching the list of class names that would be further passed in the testRunnerCommand

testDiscovery:
type: raw
mode: static
command: ls cypress/integration | sed -n 1,'10p'

Running the above command on the terminal will give a list of scenarios present in the feature files:

  • actions.spec.js
  • aliasing.spec.js
  • assertions.spec.js
  • connectors.spec.js
  • cookies.spec.js
  • local_storage.spec.js
  • navigation.spec.js
  • querying.spec.js
  • sample.spec.js
  • spies_stubs_clocks.spec.js

The testRunnerCommand contains the command that is used for triggering the test. The output fetched from the testDiscoverer command acts as an input to the testRunner command.

testRunnerCommand: npx cypress run  --spec ./cypress/integration/$test --browser=chrome-95.0 --headed --config video=false

Test Execution

The CLI option --config is used for providing the custom HyperExecute YAML file (i.e. yaml/win/.hyperexecute_autosplit.yaml for Windows and yaml/linux/.hyperexecute_autosplit.yaml for Linux).

Execute Cypress v9 tests using Autosplit mechanism on Windows platform

Run the following command on the terminal to trigger the tests in Java files with HyperExecute platform set to Windows. The --download-artifacts option is used to inform HyperExecute to download the artifacts for the job. The --force-clean-artifacts option force cleans any existing artifacts for the project.

./hyperexecute --config yaml/win/.hyperexecute_autosplit.yaml --force-clean-artifacts --download-artifacts

Execute Cypress v9 tests using Autosplit mechanism on Linux platform

Run the following command on the terminal to trigger the tests in Java files with HyperExecute platform set to Linux. The --download-artifacts option is used to inform HyperExecute to download the artifacts for the job. The --force-clean-artifacts option force cleans any existing artifacts for the project.

./hyperexecute --config yaml/linux/.hyperexecute_autosplit.yaml --force-clean-artifacts --download-artifacts

Execute Cypress v9 tests using Autosplit mechanism on Mac platform

Run the following command on the terminal to trigger the tests in Java files with HyperExecute platform set to Mac. The --download-artifacts option is used to inform HyperExecute to download the artifacts for the job. The --force-clean-artifacts option force cleans any existing artifacts for the project.

./hyperexecute --config yaml/mac/.hyperexecute_autosplit.yaml --force-clean-artifacts --download-artifacts

Visit HyperExecute Automation Dashboard to check the status of execution

Matrix Execution with Cypress v9

Matrix-based test execution is used for running the same tests across different test (or input) combinations. The Matrix directive in HyperExecute YAML file is a key:value pair where value is an array of strings.

Also, the key:value pairs are opaque strings for HyperExecute. For more information about matrix multiplexing, check out the Matrix Getting Started Guide

Core

In the current example, matrix YAML file (yaml/.hyperexecute_matrix.yaml) in the repo contains the following configuration:

globalTimeout: 90
testSuiteTimeout: 90
testSuiteStep: 90

Global timeout, testSuite timeout, and testSuite timeout are set to 90 minutes.

The target platform is set to Win. Please set the [runson] key to [mac] if the tests have to be executed on the macOS platform.

runson: win

The matrix constitutes of the following entries - classname. The entries represent the class names in the test code.

matrix:
os: [win]
browser: ["chrome-95.0","chrome-96.0","chrome-97.0","chrome-98.0","chrome-99.0","chrome-100.0","chrome-101.0","chrome-102.0","chrome-103.0","chrome-104.0","chrome-105.0"]
files: ["actions.spec.js", "aliasing.spec.js", "assertions.spec.js", "connectors.spec.js", "cookies.spec.js", "local_storage.spec.js", "navigation.spec.js", "querying.spec.js"]

The testSuites object contains a list of commands (that can be presented in an array). In the current YAML file, commands for executing the tests are put in an array (with a '-' preceding each item). The Maven command mvn test is used to run tests located in the current project. In the current project, parallel execution is achieved at the class level. The maven.repo.local parameter in Maven is used for overriding the location where the dependent Maven packages are downloaded.

testSuites:
- npx cypress run --spec ./cypress/integration/$files --browser=$browser --headed --config video=false

Pre Steps

Steps (or commands) that must run before the test execution are listed in the pre run step.

pre:
- npm install

Post Steps

Steps (or commands) that need to run after the test execution are listed in the post step. In the example, we cat the contents of yaml/.hyperexecute_matrix.yaml

post:
- cat yaml/.hyperexecute_matrix.yaml

Test Execution

The CLI option --config is used for providing the custom HyperExecute YAML file (i.e. yaml/win/.hyperexecute_matrix.yaml for Windows and yaml/linux/.hyperexecute_matrix.yaml for Linux).

Execute Cypress v9 tests using Matrix mechanism on Windows platform

Run the following command on the terminal to trigger the tests in Java files with HyperExecute platform set to Windows. The --download-artifacts option is used to inform HyperExecute to download the artifacts for the job. The --force-clean-artifacts option force cleans any existing artifacts for the project.

./hyperexecute --config yaml/win/.hyperexecute_matrix.yaml --force-clean-artifacts --download-artifacts

Execute Cypress v9 tests using Matrix mechanism on Linux platform

Run the following command on the terminal to trigger the tests in Java files with HyperExecute platform set to Linux. The --download-artifacts option is used to inform HyperExecute to download the artifacts for the job. The --force-clean-artifacts option force cleans any existing artifacts for the project.

./hyperexecute --config yaml/linux/.hyperexecute_matrix.yaml --force-clean-artifacts --download-artifacts

Execute Cypress v9 tests using Matrix mechanism on Mac platform

Run the following command on the terminal to trigger the tests in Java files with HyperExecute platform set to Mac. The --download-artifacts option is used to inform HyperExecute to download the artifacts for the job. The --force-clean-artifacts option force cleans any existing artifacts for the project.

./hyperexecute --config yaml/mac/.hyperexecute_matrix.yaml --force-clean-artifacts --download-artifacts

Visit HyperExecute Automation Dashboard to check the status of execution:

Secrets Management

If you want to use any secret keys in the YAML file, this can be set by clicking on the Secrets button on the dashboard.

All you need to do is create an environment variable that uses the secret key:

env:
PAT: ${{ .secrets.testKey }}

For any query or doubt, please feel free to contact us via 24×7 chat support or you can also drop a mail to support@lambdatest.com.
Happy testing!