w3resource

Cypress Overview


Why Cypress?

In this tutorial we will give you an overview of what Cypress is and why you should use it.

In a nutshell

Generally speaking, Cypress is a next generation front end testing tool that is built for the modern web. Cypress seeks to address the key pain points that developers and QA (Quality Assurance) engineers face when testing modern applications.

Cypress makes it possible for you to:

  • Set up tests
  • Write tests
  • Run tests
  • Debug Tests

Cypress is mostly compared to Selenium; however, Cypress is both fundamentally and architecturally different. This is because Cypress is not constrained by the same restriction as Selenium.

Cypress enables you to write tests that are faster, easier and more reliable.

Who uses cypress?

Cypress is typically used by developers and QA engineers that are building web application using modern JavaScript frameworks like React, Vue, Angular e.t.c.

You can use Cypress to test anything that runs on the browser, it enables you to write different types of tests, these tests include:

  • End-to-end tests
  • Integration tests
  • Unit tests

The Cypress ecosystem

Cypress consists of a Test Runner that is free, open source and locally installed, it also consists of a Dashboard Service for recording your tests.

  • First: Cypress enables you to set up and start writing tests every day while you build your application. It favors TDD (test driven development) at its best.
  • Later: Once you finish building the test suite and integrating Cypress with your CI Provider, now the Dashboard Service can record your test runs. You will never have to wonder why a test failed.

Features

Cypress is a very powerful testing tool, it comes fully baked, here is a list of things Cypress can do that no other testing framework is capable of doing.

  • Time Travel: When using cypress, it takes snapshots as your tests run.
  • Debuggability: it is frustrating to see tests that failed without knowing why they failed. Cypress ensures that you do not guess why your tests are failing, you can debug directly from familiar tools such as the Developer Tools. The readable errors and stack traces of Cypress makes debugging lightning fast.
  • Automatic Waiting: with Cypress you will not have to add waits and sleeps to your test, this is because Cypress will automatically wait for commands and assertions before moving on.
  • Spies, Stubs, and Clock: These verifies and controls the behavior of functions, server responses, or timers. This is the functionality that makes unit testing loveable, this same functionality is provided by Cypress.
  • Network Traffic Control: Cypress enables you to easily control, stub and test edge cases without involving your server. It enables you to stub the network in any way you want.
  • Consistent Results: The architecture of Cypress does not use Selenium or web driver. This enables you to run fast, consistent and reliable tests that are flake-free.
  • Screenshots and Videos: You can view the screenshots that are taken automatically on failure, or videos of your entire test suites when you run Cypress from the CLI.
  • Cross browser Testing: You can run tests within Firefox and Chrome-family browsers (this includes Edge and Electron) locally and you can run optimal tests in a continuous Integration pipeline.