Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Protractor is dead, long live Cypress

Protractor is dead, long live Cypress

In April this year, Angular announced the deprecation of Protractor. Protractor has been the official e2e tool since the days of AngularJs.

Although there is no official successor yet and maybe there never will, there is one tool that shines before all others: Cypress

In this talk, you will get an overview of the existing E2E frameworks and an introduction to Cypress. You will learn how it works, how to use it, and also about its pitfalls. With Cypress, we have finally e2e tests that don't fail and we can trust.

Video: https://www.youtube.com/watch?v=-lWY0X-ybME
Article: https://www.rainerhahnekamp.com/en/angular-e2e-testing-protractor-is-dead-long-live-cypress/

Rainer Hahnekamp

June 02, 2021
Tweet

More Decks by Rainer Hahnekamp

Other Decks in Programming

Transcript

  1. Protractor is dead, long live Cypress Angular Meetup Graz, 2.6.2021

    Rainer Hahnekamp Recording: https://www.youtube.com/watch?v=-lWY0X-ybME Repo: https://github.com/rainerhahnekamp/angular-cypress Article: https://www.rainerhahnekamp.com/en/angular-e2e-testing-protractor-is-dead-long-live-cypress/
  2. About me... • Rainer Hahnekamp • ANGULARarchitects.io • Trainings and

    Consultancy • > 20 Years Experience @RainerHahnekamp
  3. Agenda 1. Landscape of E2E Frameworks (Angular) 2. Why you

    should use Cypress 3. Demo Time a. Cypress Basics b. Potential Pitfalls i. Flakiness with Command Chaining ii. Asynchrony 4. Why you should not use Cypress
  4. WebDriver • Often mistaken for Selenium ◦ Selenium RC merged

    with WebDriver into Selenium 2 ◦ Selenium WebDriver is the framework's name • API along Protocol • Language Neutral • Requires a driver for each Browser
  5. WebDriver • W3C Standard • Cross-Browser Support • Known to

    be flaky • WebDriver BiDi as successor • Popular E2E Tools (very roughly) ◦ Protractor ◦ Selenium ◦ NightWatch ◦ WebDriverIO
  6. CDP (Chrome DevTools Protocol) • Debugging Tool for Chromium-based Browsers

    • Puppeteer as primary library • Playwright incl. Safari • Much more stable • Constrained to CDP-Browsers
  7. Why you should use Cypress 1. Reliable Tests 2. "Inofficial/Community

    Successor" of Protractor 3. Excellent Developer Experience
  8. Flakiness / Unreliability describe('Customers', () => { it('should add a

    customer', () => { cy.visit(''); cy.get('a').contains('Customers').click(); cy.get('a').contains('Add Customer').click(); }); });
  9. Flakiness / Unreliability • Commands are not retried when they

    are successful • Chains are multiple commands • cy.get & cy.contains are commands cy.get('a').contains('Add Customer').click(); 1 2
  10. Prevent Flakiness by Assertion describe('Customers', () => { it('add customer',

    () => { cy.visit(''); cy.get('a').contains('Customers').click(); cy.get('a').should('contain', 'Add Customer'); cy.get('a').contains('Add Customer').click(); }); });
  11. Prevent Flakiness by a better Selection describe('Customers', () => {

    it('add customer', () => { cy.visit(''); cy.get('mat-drawer a').contains('Customers').click(); cy.get('mat-drawer-content a').contains('Add Customer').click(); }); });
  12. Prevent Flakiness by a much better Selection describe('Customers', () =>

    { it('add customer', () => { cy.visit(''); cy.get('[data-test=btn-customers]').click(); cy.get('[data-test=btn-add-customer]').click(); }); });
  13. When you should not use Cypress • Cross-Browser (mobile, Safari,...)

    • iFrames: Workarounds possible • Switching domains within one test • Switch tabs
  14. Summary • Cypress (in most cases) perfect successor • Trade-Off

    between Cross-Browser and Reliability • Migration is a rewrite