Fast, easy and reliable testing for anything that runs in a browser.

Cypress is a next generation front end testing tool built for the modern web. It addresses the key pain points developers and QA engineers face when testing modern applications.
Refer to official documentation for detailed usage. →

Writing Tests#

Testing your application will require interacting with UI elements. Best practice for selecting elements in your tests is with special attributes for testing.
Refer to official documentation on writing tests for detailed usage. →

  • Add test attributes to elements of your UI.
import React from "react";
import { Button } from "@components";
export const Main: React.FC = () => {
return (
<h1 data-test="main-heading">superplate</h1>
<p>The frontend boilerplate with superpowers!</p>
<Button data-test="docs-btn-anchor">Docs</Button>
  • Now these elements can be selected in tests with cy.get
Cypress.Commands.add("getBySel", (selector, ...args) => {
return cy.get(`[data-test=${selector}]`, ...args);
Cypress.Commands.add("getBySelLike", (selector, ...args) => {
return cy.get(`[data-test*=${selector}]`, ...args);
  • Don't forget to visit the page before each test.
describe("Homepage", () => {
beforeEach(() => {
it("Brings header", () => {
cy.getBySel("main-heading").should("contain.text", "superplate");
it("Should have true href", () => {
.should("have.prop", "href")
.and("equal", "");

Refer to official documentation on selecting elemets for detailed usage. →

Running Tests#

  • Add baseUrl option to cypress configuration.
"baseUrl": "http://localhost:3000"

This will automatically prefix cy.visit() and cy.request() commands with this baseUrl.

Refer to official documentation on configuration for detailed usage. →

  • Add commands for opening Cypress Test Runner and running tests.
scripts: {
"cypress:open": "cypress open",
"cypress:run": "cypress run --config video=false",
"cypress:test": "start-server-and-test start http://localhost:3000 cypress:run"

Testing in development#

  • Start your project in dev mode
npm run dev
  • Run tests headlessly with cypress run
npm run cypress:run

Testing with production bundle#

  • Build your project
npm run build
  • run tests
npm run cypress:test

cypress run runs tests to completion. By default, cypress run will run all tests headlessly in the Electron browser.

cypress open opens the test runner and lets you run your tests invidually.

Refer to official documentation on command line for detailed usage. →

File structure#

Cypress directory is placed in the root of the project.

  • Add tsconfig.json for Cypress
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
"include": ["**/*.ts"]
  • Don't forget to exclude Cypress from main tsconfig.json
"exclude": ["cypress/*"]

All this work will be handled automatically by CLI, so you don’t need to do anything extra as long as you choose Cypress plugin during the project creation phase.

Adding Cypress to your project later#

If you didn't choose the plugin during project creation phase, you can follow the instructions below to add it.

npm install -D cypress

Refer to official documentation on installation for detailed usage. →

Last updated on by Necati Özmen