Protractor is dead, long live Cypress! - Part 1
Tags: e2e, cypress, protractor, angular
Published: 2021-07-05 07:21:18

---
title: Protractor is dead, long live Cypress! - Part 1
published: true
description: On 24th April, Angular announced the deprecation of their E2E testing tool protractor. In this article, I will provide a short overview over the differences between the various E2E frameworks, argue why you should use Cypress and – in the second part – help you with the first steps.
tags: E2E, Cypress, Protractor, angular
cover_image: https://www.rainerhahnekamp.com/wp-content/uploads/2021/06/2021-05-31.png
series: angular-cypress
canonical_url: https://www.rainerhahnekamp.com/en/angular-e2e-testing-protractor-is-dead-long-live-cypress/
---

## Table of Contents
  * [Landscape of E2E testing frameworks](#landscape)
    * [WebDriver-Based](#webdriver)
    * [Chrome DevTools Protocol](#cdp)
    * [Flakiness vs. Cross-Browser](#flakiness)
  * [Why you should use Cypress](#cypress-advantages)
  * [Why you should not use Cypress](#cypress-disadvantages)
  * [Summary](#summary)
  * [Further Reading](#further-reading)

On 24th April, Angular announced the deprecation of their end-to-end (E2E) testing tool, Protractor. It remains unclear whether there will be a successor or if Angular will delegate this to its users. At the time of this writing, WebDriver.IO, TestCafé and Cypress have come up with schematics for the Angular CLI.

In this article, I will provide a short overview of the differences between the various E2E frameworks and explain why you should use Cypress. In the follow-up to this article, I will help you get started with Cypress.

If you prefer watching over reading, then this recording of my talk is for you:
{% youtube -lWY0X-ybME %}

## Landscape of E2E testing frameworks <a name="landscape"></a>

### WebDriver-Based <a name="webdriver"></a>

We can roughly split the available tools into two groups. Those based on WebDriver and those that operate on the Chrome DevTools Protocol (CDP).

Selenium was released in 2004. It merged with a similar tool called WebDriver. Selenium is still a major player and Protractor is, more or less, a wrapper around it.

With Selenium/WebDriver, developers have a common API to automate a browser. Every supported browser provides a driver which WebDriver uses to make these frameworks cross-browser capable. This means that you can run the same test on Safari, Chrome, mobile browsers, etc.

Over time, WebDriver, the core technology in Selenium, became a W3C standard. That opened doors for other vendors to create their own frameworks based on WebDriver.

Unfortunately, WebDriver-based tests have a flaky reputation. If you run the tests multiple times under the same circumstances, they may fail or they may succeed. That is extremely bad for a testing framework. You spend a considerable amount of time building tests that should guarantee the stability of the application and then you can't even trust the tests’ results.


### Chrome DevTools Protocol <a name="cdp"></a>

Two quite popular alternatives are Puppeteer and Playwright. They don’t rely on WebDriver but talk directly to the browser via the Chrome DevTools Protocol (CDP). This gives them much better control which leads to more stable tests.

CDP binds to the Chromium-based browsers including Chrome and Edge. Although Firefox supports CDP as well, the kind of cross-browser testing WebDriver enables is not possible.

Some of Puppeteer’s original developers are behind Playwright. So one could see Playwright as a rewrite of Puppeteer. It uses CDP as well but also supports Safari because it ships with patched browsers.

WebdriverIO is a hybrid framework. It provides both access to CDP and WebDriver.

In which category does Cypress fall? Cypress relies on CDP but, in contrast to Puppeteer, Cypress only uses CDP to manage the tests. The tests themselves don't use CDP at all but run directly in the browser. There is no layer between the tests and the browser anymore. Your test code has direct access to the DOM and not an indirect one via CDP or WebDriver. Test and application code are one.

As it happens, that's the same approach that Selenium took before it merged with WebDriver. Looks like history repeats itself.

## Flakiness vs. Cross-Browser <a name="flakiness"></a>

From a very high-level view, the more abstraction we have between our tests and the browser, the flakier tests tend to become. On the other hand, abstraction makes it easier to do cross-browser testing. The closer we get the browser the more stable the tests become. However, we must accept that we can only run the test in one particular browser technology, i.e. Chromium.
In the future, all browsers might support CDP or the upcoming WebDriver BiDi will bring stability into the WebDriver world. But things are still evolving.

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5q1alums6mmzyjnrz4hw.png" alt="Landscape of E2E Frameworks">
  <figcaption>Landscape of E2E Frameworks</figcaption>
</figure>

## Why you should use Cypress <a name="cypress-advantages"></a>

First, Cypress does not use WebDriver but runs its tests directly in the browser. These make the tests stable and reliable. Exactly what we wanted in the first place.

The second reason is the development experience (DX). Cypress' authors invested a lot of effort in making it as easy to use as possible. This does not just mean that the API is easy to use. The tooling, the community work, and especially the documentation are just fantastic.

OK, so Cypress is better than Protractor. Why should you pick Cypress over any other E2E library?

As Angular developers, we always appreciated that we got an "opinionated framework" which pre-selected various tools for us. Although it might look like Angular leaves the spot for E2E empty, there is another big player: Nx has been providing the best tools for Angular applications for quite some years.

Nx is a wrapper around the CLI. It started out as a candidate for MonoRepositories but over the years became more and more of an Angular CLI++. In fact, I personally would always pick nx, if I start a new Angular application. There is no lock-in and no overhead. I just get better tooling and can stay with the Angular CLI.

And guess what? Nx replaced Protractor with Cypress. So nx takes care that Angular and Cypress work well together.

The last argument is the usage of Cypress among Angular developers. Before the deprecation was made public, Angular did a survey. They asked their users what E2E they are using. That survey showed 64% for Cypress. You call that a landslide victory in politics. And please remember, that was at a time when Protractor was the official tool! Protractor ended up with only 19%.


<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/md7w2wcl581oom0awu9k.png" alt="Usage of E2E frameworks among Angular Devs">
  <figcaption>Source: https://github.com/angular/protractor/issues/5502
</figcaption>
</figure>

## Why you should not use Cypress <a name="cypress-disadvantages"></a>

Depending on your use case, Cypress might not fit your needs:

- No cross-browser testing: If you need to run your e2e tests in Safari, other browsers or even on mobiles devices, you need to use another tool. Cypress is definitely the wrong choice.
- Switching domains within one test: If your applications spans across multiple domains, you will also not be happy with Cypress.
- Switching tabs: Also not possible.

This is just a logical consequence if you think about how Cypress works. Tests run inside the browser and vanish if you change the URL or the tab.

## Summary <a name="summary"></a>

Cypress gives you both stability and a great developer experience. The majority of Angular developers use it already.
If you are running E2E in Protractor, now is the time to migrate! If you haven't written E2E until now, take a look at Cypress. You will be surprised how easy it is.
Switching to Cypress means rewriting your E2E tests. You can do that in an incremental way. Cypress and Protractor don't exclude each other. They can be run in the same Angular project.
Be aware that Cypress might not fit your needs. If cross-browser support is an absolute must, you should check out alternatives like WebDriverIO and others mentioned above.

## Outlook

In the second part, we will do our first steps with Cypress.

## Further Reading
- [WebDriver/RemoteProtocol](https://wiki.mozilla.org/WebDriver/RemoteProtocol)
- [W3C WebDriver protocol](https://w3c.github.io/webdriver/webdriver-spec.html)
- [Future of Angular E2E & Plans for Protractor · Issue #5502 · angular/protractor](https://github.com/angular/protractor/issues/5502)
- [Automation Protocols](https://webdriver.io/docs/automationProtocols)
- [Playwright vs. Puppeteer](https://blog.logrocket.com/playwright-vs-puppeteer/)
- [Cypress vs. Selenium: Why Cypress is the better option](https://blog.logrocket.com/cypress-io-the-selenium-killer)
- [What is Selenium RC : Difference from Webdriver](https://www.browserstack.com/guide/selenium-rc-tutorial)
- [Nightwatch.js | Node.js powered End-to-End testing framework](https://nightwatchjs.org/gettingstarted/)
- [Cypress vs. Other Test Runners](https://glebbahmutov.com/blog/cypress-vs-other-test-runners/)
- Book: Learning Selenium Testing Tools – Third Edition, Raghavendra Prasad MG