If you’ve ever struggled with the complexities of traditional testing frameworks like Selenium—setting up drivers, dealing with flaky tests, and waiting forever for things to load—Cypress will feel like a lifesaver.
Why? Because Cypress simplifies your testing process in ways that save both time and energy. Imagine being able to test your web app in real time, automatically waiting for elements to load, and having a robust tool that integrates seamlessly with modern JavaScript frameworks like React and Angular. It’s fast, reliable, and ideal for today’s agile development workflows.
In this guide, we'll show you how to do Cypress testing - everything! From the installation to advanced Cypress testing techniques.
Technically speaking, Cypress is a modern JavaScript-based end-to-end testing framework designed to run in the browser using Node.js. It was built specifically for testing web applications, with features tailored to frontend developers' needs. But, let’s step out of the tech jargon for a moment.
In simple terms, Cypress helps you see your website through the eyes of your users. It interacts with your app the way a real person would—by clicking buttons, filling out forms, and navigating pages. Whether you're testing how your login form handles incorrect passwords or how fast your shopping cart loads, Cypress is designed to mimic these real-world scenarios.
And the best part? It’s all done in real-time, making the process super interactive.
Let’s dive into what makes Cypress such a powerful tool:
Setting up Cypress is surprisingly easy, especially compared to older testing frameworks like Selenium, where multiple configurations are necessary. With Cypress, you can be up and running in just a few steps—no more fumbling around with drivers or complex setups. Let’s break it down.
Installing Cypress as a dev dependency ensures it’s only used in the development environment and not bundled into your production code. This keeps your production build lightweight and focused on delivering your app’s core functionality, while Cypress stays in your development environment to handle testing.
To do this, open your terminal and make sure you’re in the root directory of the project you want to test. You can do this with the cd command.
cd /path-to-your-project
Now that you’re in your project directory, install Cypress by running the following command:
npm install cypress --save-dev
This command tells npm to download Cypress and install it as a dev dependency. The --save-dev flag is critical here because it tells npm to add Cypress to the devDependencies section of your package.json file. This ensures that Cypress is only used during development, making it a best practice in modern web development.
After installation, confirm that Cypress is installed by checking the node_modules directory and ensuring the cypress folder is present. You can also look for Cypress in your package.json under devDependencies.
Once Cypress is installed, you can launch it using a simple command. Run the following command to launch the Cypress Test Runner:
npx cypress open
Using npx ensures you’re running the Cypress executable directly from your node_modules directory without needing to install it globally. This is the preferred method because it avoids global dependencies that could conflict with other projects.
Upon running the command, the Cypress Test Runner will launch in a separate window. The Test Runner is a visual interface where you can manage, write, and execute your tests in real-time. Think of it as your command center for running tests and analyzing their results.
Cypress will automatically create a default folder structure in your project, including the following directories:
This directory structure is crucial for organizing your tests, fixtures (mock data), and support files. It’s designed to keep your tests modular and easy to maintain.
To help you get started, Cypress includes several example tests right out of the box.
1. Locate Example Tests: Navigate to the /cypress/integration/ folder, and you’ll find example test files already set up for you. These example tests are a great way to get familiar with Cypress’s API and the types of commands you’ll be using frequently.
2. Run a Test: Simply click on one of the example test files within the Cypress Test Runner, and watch as Cypress opens a browser and executes the test. You’ll see the test steps play out in the browser itself, with each step logged in real-time in the Test Runner’s command log.
Every Cypress test follows a standard structure that includes two core components: describe blocks, which group related tests, and it blocks, which define individual test cases.
Let’s look at a clean and concise example:
describe('My First Test', () => {
it('Visits a website and checks the title', () => {
cy.visit('https://example.com')
cy.title().should('include', 'Example Domain')
})
})
What this code snippet means:
Of course, we recommend that you read through Cypress documentation to gain deeper understanding of Cypress syntax.
beforeEach(() => {
cy.clearCookies();
cy.clearLocalStorage();
cy.reload();
});
cy.intercept('GET', '/api/users', { fixture: 'users.json' }).as('getUsers');
cy.visit('/users');
cy.wait('@getUsers');
Cypress.Commands.add('login', (username, password) => {
cy.visit('/login');
cy.get('input[name=username]').type(username);
cy.get('input[name=password]').type(password);
cy.get('button[type=submit]').click();
});
cy.get('button').should('be.visible').click();
cy.url().should('include', '/dashboard');
cypress run --record --parallel --group <group-name>
cy.get('[data-cy=submit-button]').click();
Cypress takes the guesswork out of debugging by integrating seamlessly with Chrome DevTools. When a test fails, you don’t have to search through endless logs or re-run the test multiple times to figure out what went wrong. Instead, Cypress gives you real-time feedback, making it easy to pinpoint the exact issue. You can use:
Cypress also excels in how it handles test failures. When a test fails, Cypress doesn’t just leave you with a generic error message. It provides a full trace of the failure, including a detailed explanation of the error, a screenshot of the browser at the moment of failure, and even a video of the test execution if video recording is enabled.
Here's a quick comparison of Cypress vs other open-source frameworks for you:
Criteria | Cypress | Selenium | Playwright |
Primary Language | JavaScript (Node.js) | Multiple (Java, Python, C#, Ruby, JavaScript) | JavaScript, Python, C#, Java |
Supported Browsers | Chrome, Firefox, Edge, Electron | Chrome, Firefox, Edge, Safari, IE | Chrome, Firefox, Edge, WebKit |
Cross-browser Support | Limited (no Safari or IE) | Full support for all major browsers | Full support, including WebKit (for Safari-like behavior) |
Setup Complexity | Easy, quick to install with NPM | Moderate, requires WebDriver setup | Easy, built-in browser binaries for faster setup |
Speed | Fast due to direct execution in the browser | Slower due to WebDriver architecture (server-client model) | Fast, like Cypress, due to native browser control |
Test Reliability | High (minimal flakiness, automatic waits) | Lower (prone to flakiness, requires explicit waits) | High (automatic waits, handles flakiness well) |
Parallel Execution | Built-in support through dashboard (paid) | Requires configuration (grid setup) | Built-in support for parallel testing |
API Testing | Supports both frontend and API testing within same framework | Not built-in, requires additional libraries | Supports API testing alongside web testing |
Architecture | Runs directly in the browser with Node.js | Uses WebDriver to interact with browsers via browser drivers | Direct browser control like Cypress |
Debugging Capabilities | Excellent (real-time reloading, time travel, detailed logs) | Good (browser developer tools, log analysis) | Excellent (tracing, screenshots, network activity) |
Flakiness | Low, due to control over browser and automatic waits | Higher, requires more manual handling of waits | Low, automatic handling of waits and retries |
Community & Ecosystem | Growing, but smaller compared to Selenium | Very large, mature, and widely used | Growing rapidly, strong backing by Microsoft |
Mobile Testing Support | No direct support | Supports mobile testing via Appium | No direct support, but can emulate mobile browsers |
Multiple Tabs/Windows | Limited (no multi-tab support) | Full support for multiple tabs | Full support for multiple tabs and browser contexts |
Headless Mode | Yes, supports headless mode for Chrome, Firefox, Edge | Yes, via drivers | Yes, supports headless mode for all supported browsers |
Integration with CI/CD | Easy integration with Jenkins, GitHub Actions, etc. | Requires more setup | Easy integration, built-in tools for CI/CD |
Open Source/License | Open-source, with paid features (Dashboard) | Fully open-source | Fully open-source |
Cypress is an amazing framework, no doubt. However, you know the struggle. We’ve all been there—running a test suite that works perfectly one day, only to have it mysteriously fail the next. Flaky tests are those unreliable ones that randomly pass or fail, often due to timing issues, async calls, or dependencies on third-party services. They leave you scratching your head, wondering, “Did the code break, or is the test just acting up?”
Then comes the setup headaches. Cypress is among the easier ones to set up. Some testing frameworks require elaborate setup processes with intricate dependencies, browser drivers, and configurations, such as Selenium, just getting your environment up and running can feel like more of a coding project than your actual app development.
And then when tests fail, sometimes you’re left staring at cryptic error logs or digging through endless console messages. Figuring out what went wrong can take longer than writing the actual test.
The solution? No-code/low-code testing tools.
It's no buzzword. No-code/low-code testing tools simplify your testing life in so many ways.
1. Faster Test Creation
Traditional code-based testing can be slow, requiring developers to write test scripts for each scenario. On the other hand, Katalon Studio offers up to 3 testing modes for maximum flexibility:
2. Lower Technical Barrier
No-code/low-code tools empower non-technical team members like QA engineers, business analysts, or even stakeholders to participate in testing. These tools reduce dependency on the development team for creating or maintaining tests, making testing more collaborative.
3. Maintenance Made Easy
As codebases evolve, traditional test scripts often break due to changing elements or workflows, leading to high test maintenance costs. No-code tools simplify this by offering self-healing tests, where the tool automatically adapts to minor changes in the application’s UI or logic.
4. Scalability Without Complexity
No-code tools make it easy to scale test coverage without the complexity of writing more code. You can rapidly create new tests by cloning or modifying existing workflows and scale testing across multiple environments with minimal effort. In Katalon, you can test across a wide range of browsers, devices, and operating systems within one place.