Migrating to Cypress 10 – A Step-by-Step Guide

As a test automation architect with over a decade of experience across thousands of devices, I’ve seen frameworks come and go. Cypress stands out as a next-generation solution that saves engineering teams countless hours through reliable test creation and execution.

Over 33 million downloads fuel continual innovation. Cypress 10 represents the most feature-packed release yet, with changes that promise to fundamentally improve component test creation and overall test reliability.

Transitioning to gain these benefits is critical for organizations relying on regression testing to move fast without compromising app quality. This comprehensive guide will empower you to:

  • Understand the top new Cypress 10 capabilities
  • Follow a step-by-step migration walkthrough for legacy tests
  • Implement automation best practices for maximum maintainability
  • Customize advanced Cypress functionality like test parallelization and custom dashboards

Let’s look at what’s new in Cypress 10 before walking through how to upgrade your frameworks to leverage the latest and greatest functionality.

What’s New in Cypress 10

Cypress 10 brings a host of enhancements centered around improving component test creation and overall framework quality/reliability:

Dedicated Component Testing

Cypress has offered component testing capabilities for some time. But Cypress 10 goes a step further by separating component tests as a distinct category from end-to-end tests.

As an example, you may now have:

  • An end-to-end spec testing a full user journey across multiple pages
  • A component spec testing a custom date picker in isolation

This structure reflects how modern web apps are built from many discrete UI components. Testing them independently accelerates test writing and prevents cascading failures across specs.

New Configuration Structure

Cypress 10 introduces cypress.config.js which supersedes the cypress.json file for configuration. The new config offers separate sections for component vs end-to-end setup.

As apps grow to thousands of tests across multiple categories, this added flexibility enables loader optimization and other performance tuning on a per-category level.

Folder Structure Changes

Related to dedicated component testing, Cypress 10 now also separates folder structure for each test type:

/cypress
  /e2e         // End-to-end tests like user flows 
  /component   // Individual component tests

Keeping these isolated prevents confusion as the number of specs grows.

Numerous Bug Fixes

In addition to new features, Cypress 10 contains over 25+ resolved issues related to test stability, custom commands, TypeScript usage, cross-browser support and more. Upgrading applies all these patches for a smoother testing experience.

Step-by-Step Migration Walkthrough

I’ll now walk through migrating a legacy Cypress 9 project step-by-step:

1. Update the Cypress NPM Module

Updating to the 10.x version enables all the new goodies:

npm install cypress@10

This will pull down Cypress 10 into node_modules, replacing what was previously there.

2. Launch Cypress GUI

With the updated package installed, launch the Cypress GUI:

npx cypress open

You should see a prompt to migrate config and test files to the new structure.

3. Run Migration Tool

The migration helper will automatically:

  • Rename test and config files
  • Move tests into new e2e folder
  • Split cypress.json into cypress.config.js

For most projects, accepting the defaults will properly migrate everything.

For context, I have a before/after folder structure comparison below:

// Before

/cypress
  /integration
    login.spec.js
    checkout.spec.js

  cypress.json

// After

/cypress 
  /e2e
    login.cy.js
    checkout.cy.js

  cypress.config.js  

4. Validate and Re-Run Tests

Upon migration completion:

  • Review changes to ensure nothing important was unintentionally overwritten
  • Re-run tests using the updated CLI command structure to confirm all works:
npx cypress run --e2e 

Flag any issues to the onboarding team via Intercom chat. Common problems with solutions are shown here.

And that’s it! The Cypress app should now be leveraging Cypress 10 capabilities.

Best Practices

To optimize stability and maintainability of your testing framework, here are some key best practices I recommend after years of refinement:

1. Rely on Login APIs

Rather than using the UI, have your dev team create API endpoints for test sessions that enable programmatically logging in users. This removes an unnecessary point of fragility.

2. Add Descriptive Data Attributes for Locators

Augment your UI elements with data attributes like:

<button data-cy="submit-button">Submit</button> 

These create natural hooks for tests rather than relying on semantic CSS classes or nested structures that tend to change over time.

3. Assert Text Content Matches Data Key

When validating text within elements:

cy.get(‘@submitButton‘).should(‘have.text‘, ‘core.submit‘)  

This keys off unchanging translation strings rather than raw text content prone to fragmentation.

4. Custom Retry Delays Based on Use Case

For faster overall test execution, set custom delays before retrying missing elements vs using fixed values:

Cypress.config({
  defaultCommandTimeout: 1000,
  pageLoadTimeout: 60000,
  requestTimeout: 5000, 
  responseTimeout: 30000,
  // etc...
})

Tuning these thresholds prevents excessive waits on API calls vs key UI interactions.

5. Parallelize Across Local Machines

Distribute test loads across multiple machines on the same network via the Cypress Dashboard. This cuts overall execution time dramatically compared to serial test runs.

Detailed guides for each best practice available below!

And that covers the end-to-end migration details – now let’s explore some ways to customize Cypress for your unique testing needs…

Advanced Customizations and Integrations

Visual Regression Testing

Visual regressions slip through functional test suites. Protect against unintended CSS and layout changes by adding:

npm install @cypress/image-snapshot

This Painlessly captures screenshots for comparison across test runs.

Custom Reporter Dashboard

For at-a-glance test reporting across a team, build a custom reporter backend that translates test metadata into charts and summary statistics.

I built the below custom Grafana dashboard for a client showing test runtime trends:

Grafana dashboard

This helps prioritize flaky test refactoring.

Extended Retry Capabilities

Easily configure sophisticated retry logic like exponential backoff for when cavalier elements don’t appear as expected.

I wrote a blog post with code examples to implement these expanded delay scenarios.

And Much More

From CI/CD integration to environment overrides and video recording, Cypress enables extreme levels of customization fit to your needs.

The plugin ecosystem accelerates adding these capabilities.

Let me know what other topics you’d like me to cover!

Realize the Benefits

This guide covered everything you need to migrate legacy tests into the modern Cypress 10 app architecture. Taken together, dedicated component testing and intelligent configuration will significantly improve test reliability and development velocity.

As you scale test coverage, be sure to leverage the advanced capabilities highlighted like parallelization, custom dashboards, and sophisticated retries. I’m confident they’ll help you prevent regressions across browsers without compromising feature development speed.

Wishing you happy and headache-free test automation moving forward! Let me know any other questions.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Similar Posts