
As web applications become increasingly complex, ensuring compatibility across multiple browsers has never been more important.
While testing your application, it's essential to verify how it behaves on different browsers, especially with modern frameworks like Cypress.
Cypress, a popular end-to-end testing framework, offers native support for testing in several major browsers like Chrome, Firefox, and Electron, and even introduces experimental support for WebKit (the engine behind Safari).
However, understanding the limits of Cypress’s browser support and knowing how to configure and run tests across various browsers is key to achieving thorough test coverage.
This article explores the browsers that Cypress supports, how to configure them, and the best practices for running tests across different browsers for reliable, cross-platform web applications.
Cypress is an end-to-end testing framework that interacts directly with the browser, providing faster and more reliable test execution compared to traditional WebDriver-based tools. Cypress’s architecture runs tests inside the browser, unlike WebDriver, which relies on a separate server to communicate with the browser.
1. Architecture: Cypress runs inside the browser, executing commands in real-time, while WebDriver uses an external server to communicate with the browser, causing delays.
2. Speed & Reliability: Cypress provides faster and more reliable tests due to its direct control over the browser, whereas WebDriver can be slower and more prone to timing issues.
3. Debugging: Cypress offers real-time, interactive debugging within the browser, while WebDriver typically requires external tools for debugging.
4. Browser Support: Cypress supports modern browsers like Chrome, Firefox, and Electron, with experimental WebKit support. For broader browser support, WebDriver is more versatile, supporting a wider range of browsers, including older versions and Internet Explorer.
5. Mobile Testing: Cypress doesn’t natively support mobile testing but can simulate mobile environments via viewport adjustments. WebDriver (with Appium) is better suited for mobile testing across a wide range of devices.
Cypress supports several modern browsers, allowing you to test your web application across different environments.
While Cypress doesn’t support every browser on the market, it provides robust support for the most commonly used browsers, ensuring broad compatibility and real-world test coverage.
1. Chrome-family Browsers
All of these Chrome-family browsers offer full support for modern web standards and Cypress commands, ensuring stable test execution.
2. Firefox
3. Electron
4. WebKit (Experimental)
5. Browsers Not Natively Supported
One of the key features of Cypress is its ability to run tests directly inside modern browsers, ensuring real-time interaction with your application. Here's how Cypress handles browser detection and launching for your tests:
When you install Cypress, it automatically detects all the browsers available on your system. This includes popular browsers like Chrome, Chromium, Firefox, and Electron.
On macOS, if you have Safari installed, Cypress can also detect WebKit (Safari's engine) as an available option for testing.
Once Cypress is installed, it doesn't require any complex setup or configuration to detect browsers; it will automatically list the supported browsers that are installed on your system.
When running tests, Cypress queries your local machine’s browser installations and dynamically populates the available options, ensuring that you can run tests in any of the supported browsers.
For instance:
Once Cypress detects the installed browsers, you can specify which browser you want to run your tests in. You can do this either interactively through the Cypress Test Runner (UI mode) or via the command line interface (CLI).
If you’re running tests in Cypress Open mode, the available browsers will be listed in the UI. You can simply click on the desired browser, and Cypress will launch it to execute your tests.
npx cypress open
For headless testing or running tests from a script (e.g., in a CI pipeline), you can specify the browser directly using the --browser flag.
The following command runs tests in Chrome:
npx cypress run --browser chrome
Similarly, for Firefox, you can specify:
npx cypress run --browser firefox
You can also run tests on specific browsers programmatically, like so:
npx cypress run --browser electron
By using the --browser flag, Cypress runs the tests in the chosen browser, regardless of the default browser configuration.
Cypress ensures that it runs tests in the latest stable versions of the supported browsers (Chrome, Firefox, Electron). When Cypress detects a browser, it doesn’t simply check if the browser is installed—it also verifies the version to ensure compatibility. For example:
If you need to test with a specific version of a browser that isn't automatically detected or supported, you can install the required version manually and ensure it's available in your system’s environment variables.
If you don’t specify a browser when running Cypress, it will default to the first browser listed in the available browsers list. Typically, this is Electron, but it can vary depending on your configuration or operating system.
For example:
npx cypress run
This command will run the tests using the default browser (Electron) unless another browser is specified.
For more advanced setups, Cypress allows you to pass custom browser profiles when running tests, particularly for Chrome. This can be useful if you need to run tests with custom browser settings, like a specific extension or different user data.
To use a custom Chrome profile, you can specify additional arguments using the --config option:
npx cypress run --browser chrome --config chromeWebSecurity=false
This allows you to modify specific behaviors of the browser during test execution, like disabling web security for certain tests or changing viewport sizes dynamically.
Cypress allows you to run your test suite on multiple browsers in parallel, providing coverage for different environments without needing to write separate test scripts.
For example, you can execute tests on Chrome and Firefox by running separate commands:
npx cypress run --browser chrome
npx cypress run --browser firefox
For CI/CD pipelines, you can integrate these commands to run the same tests across multiple browsers automatically, ensuring cross-browser compatibility for your web application.
While Cypress automatically detects and launches browsers, you may need to customize settings depending on the browser you're testing with.
For instance, Cypress provides options for configuring viewport sizes, time zones, and user agents.
These configurations can be set in the cypress.json configuration file, or they can be passed as command line arguments.
Example configurations:
{
"viewportWidth": 1280,
"viewportHeight": 800
}
This config ensures that Cypress uses a consistent viewport size across different browsers and tests.
One of the key features of Cypress is its ability to run tests in various modern browsers, ensuring that your web application behaves as expected across different environments.
While Cypress doesn’t support all browsers natively, it does allow you to run your tests on the most widely used browsers, including Chrome, Firefox, Electron, and WebKit (experimental support for Safari). Here’s how you can run Cypress tests in different browsers.
Cypress Open provides an interactive test running environment, where you can choose which browser to run your tests in. This is the most straightforward way to execute tests in multiple browsers during development. The steps include:
1. Launch Cypress Open
npx cypress open
2. Select Your Browser
Once Cypress Open is launched, you'll see a list of supported browsers installed on your machine. Simply click on the browser you wish to use (e.g., Chrome, Firefox, Edge, Electron) to start running your tests interactively in that browser.
3. Run the Tests
After selecting a browser, Cypress will run the tests in that browser. You’ll be able to see real-time logs, snapshots, and interact with the application directly as the tests execute.
For automated testing, especially in CI/CD pipelines, headless mode is typically preferred. In this mode, Cypress runs tests without launching a visible browser window. This improves execution speed and is ideal for continuous integration environments.
To run tests in headless mode, use the --browser flag followed by the browser you want to use. Here’s how you can run tests in different browsers using headless mode:
1. Run Tests in Chrome (Headless)
npx cypress run --browser chrome
This will run your tests in Chrome without opening the browser window.
2. Run Tests in Firefox (Headless)
npx cypress run --browser firefox
This command runs your tests in Firefox in headless mode.
3. Run Tests in Electron (Headless)
npx cypress run --browser electron
Electron is the default headless browser used by Cypress, and it runs tests faster, making it ideal for CI workflows.
4. Run Tests in WebKit (Experimental)
npx cypress run --browser webkit
WebKit, which powers Safari, is available as an experimental feature in Cypress. This allows you to run tests similar to Safari without having to use the full browser.
In Cypress, you can run the same test suite in multiple browsers to ensure that your web application performs consistently across different environments. To do this, you can execute the tests in multiple browsers in succession or in parallel, depending on your workflow.
Example: You can run the same tests on Chrome, Firefox, and Electron by running the following commands separately.
1. Run Tests in Chrome
npx cypress run --browser chrome
2. Run Tests in Firefox
npx cypress run --browser firefox
3. Run Tests in Electron
npx cypress run --browser electron
If you want to speed up execution, consider running tests in multiple browsers in parallel by using CI/CD tools, such as GitHub Actions, CircleCI, or Jenkins, that allow running multiple jobs at once.
In a CI/CD pipeline, you may want to run tests on different browsers automatically to ensure cross-browser compatibility. This is typically done by specifying the browser in the pipeline configuration file.
Example with GitHub Actions: Here’s how you can set up your GitHub Actions workflow to run tests on Chrome and Firefox.
name: Cypress Tests
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run Cypress tests on Chrome
run: npx cypress run --browser chrome
- name: Run Cypress tests on Firefox
run: npx cypress run --browser firefox
This configuration ensures that Cypress tests are run in Chrome and Firefox every time you push changes to the main branch.
While Cypress supports popular modern browsers like Chrome, Firefox, and Electron, there are some notable limitations:
To ensure your web application performs consistently across different browsers, it’s essential to follow best practices that address common challenges in cross-browser testing:
To expand Cypress's native browser support and test on a broader range of environments, integrating with cloud-based platforms is highly effective. Here’s how cloud platforms help extend your browser coverage:
Cypress provides powerful and efficient cross-browser testing capabilities, ensuring that your web applications are thoroughly tested across modern browsers like Chrome, Firefox, Electron, and WebKit. However, for comprehensive coverage, legacy browsers or real mobile devices, integrating Cypress with cloud platforms like BrowserStack Automate can extend your testing capabilities even further.
BrowserStack Automate allows you to run Cypress tests across a wide range of browsers, versions, and devices in the cloud, without the need for local infrastructure. This ensures that your application works flawlessly across all platforms, helping you deliver a seamless user experience no matter the browser or device your users prefer.
Get visual proof, steps to reproduce and technical logs with one click
Try Bird on your next bug - you’ll love it
“Game changer”
Julie, Head of QA
Try Bird later, from your desktop