JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionstesting
Next
testing
senior
e2e

What are E2E tests and when should you use Cypress vs Playwright?

e2e
cypress
playwright
browser-testing
automation
Quick Answer

E2E tests simulate real user scenarios across the full application stack. Cypress excels in developer experience with time-travel debugging and automatic waiting. Playwright offers cross-browser support, better parallelization, and handles multiple contexts.

Detailed Explanation

E2E Testing:

  • Test complete user flows
  • Real browser, real network
  • Slowest but most realistic
  • Catch integration issues

Cypress:

  • Excellent DX and debugging
  • Time-travel snapshots
  • Automatic waiting
  • Chrome-focused (other browsers experimental)
  • Same-origin limitation
  • Interactive test runner

Playwright:

  • True cross-browser (Chrome, Firefox, Safari)
  • Better parallel execution
  • Multiple browser contexts
  • Network interception
  • Mobile emulation
  • Faster execution

When to Use:

  • Cypress: Simpler apps, great debugging
  • Playwright: Cross-browser needs, complex scenarios

Code Examples

Cypress E2E test
// cypress/e2e/auth.cy.js
describe('Authentication', () => {
  beforeEach(() => {
    cy.visit('/login');
  });

  it('logs in successfully with valid credentials', () => {
    cy.get('[data-cy=email]').type('user@example.com');
    cy.get('[data-cy=password]').type('password123');
    cy.get('[data-cy=submit]').click();

    // Cypress auto-waits for elements
    cy.url().should('include', '/dashboard');
    cy.get('[data-cy=welcome]').should('contain', 'Welcome');
  });

  it('shows error for invalid credentials', () => {
    cy.get('[data-cy=email]').type('wrong@example.com');
    cy.get('[data-cy=password]').type('wrongpassword');
    cy.get('[data-cy=submit]').click();

    cy.get('[data-cy=error]').should('be.visible')
      .and('contain', 'Invalid credentials');
  });

  it('intercepts API calls', () => {
    cy.intercept('POST', '/api/login', {
      statusCode: 200,
      body: { token: 'fake-token', user: { name: 'Test User' } }
    }).as('loginRequest');

    cy.get('[data-cy=email]').type('user@example.com');
    cy.get('[data-cy=password]').type('password');
    cy.get('[data-cy=submit]').click();

    cy.wait('@loginRequest');
    cy.url().should('include', '/dashboard');
  });
});

Resources

Cypress Documentation

docs

Playwright Documentation

docs

Related Questions

What is the difference between unit tests and integration tests?

mid
integration

How do you design a testing strategy for a large application?

senior
strategy
Next
How do you design a testing strategy for a large application?