How to Launch Safari Browser in Cypress

Profile picture for user devraj
Submitted by devraj on

Cypress has experimental support for the Safari browser engine known as Webkit. Webkit support is provided in Cypress version 10.8.0. Therefore, you need to use version 10.8.0 or higher.

Table of Content

  1. Experimental Support
  2. Install Playwright-webkit package
  3. Launch Safari from Test Runner
  4. Launch Safari from Command Line
  5. Video Tutorial

Experimental Support

This feature is added with the help of Playwright's contributor and uses Playwright's build of WebKit. You need to install playwright-webkit package and enable the configuration for it.

Since support has been provided in the recent version and is experimental, some commands like origin and session might not work. You can check the open issue here and open an issue you encounter if not listed here.

Install Playwright-webkit package

To install and enable the playwright-webkit package follow the below step:

Step 1: set experimentalWebKitSupport to true in your cypress.config.js or cypress.config.ts

export default defineConfig({
  experimentalWebKitSupport: true,

Step 2: Install Package

npm install --save-dev playwright-webkit

If you are using a Linux machine, install additional dependencies using the below command.

npx playwright install-deps webkit

Launch Webkit (Safari Engine) Browser from Test Runner

Once you install the webkit package, you will see an additional webkit option in the runner. You can execute your tests as you execute for other browsers.

execute cypress test on safari

Launch Webkit (Safari Engine) Browser from Command Line

To execute from the command line, use the webkit value for the --browser option.

npx cypress run --browser webkit --spec cypress/e2e/