DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Real Device Cloud Testing: All You Need to Know
  • Simplified Development With Azure DevOps
  • Developers Are Scaling Faster Than Ever: Here’s How Security Can Keep Up
  • Scaling Your Testing Efforts With Cloud-Based Testing Tools

Trending

  • Bad Software Examples: How Much Can Poor Code Hurt You?
  • Top 7 Best Practices DevSecOps Team Must Implement in the CI/CD Process
  • Hugging Face Is the New GitHub for LLMs
  • How To Optimize Feature Sets With Genetic Algorithms
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Cypress Feature “Test Replay” Launched: Let’s Play With Test Replay

Cypress Feature “Test Replay” Launched: Let’s Play With Test Replay

Test Replay is a valuable feature that can help developers debug failed and flaky test runs more effectively. Learn more!

Kailash Pathak user avatar by
Kailash Pathak
·
Sep. 06, 23 · Tutorial
Like (1)
Save
Tweet
Share
2.34K Views

Join the DZone community and get the full member experience.

Join For Free

Problem Statement

Before Cypress v13, test failures in CI have historically been captured through screenshots, videos, and stack trace outputs, but these artifacts provide limited information.

So Cypress comes with a new feature Test Replay in version 13.0.0. The introduction of features like “Test Replay” in Cypress v13 aims to bridge this gap by providing developers with a way to replay the exact test run and inspect various aspects of it, such as DOM interactions, network requests, console logs, JavaScript errors, and more

What Is Test Replay?

Test Replay is a valuable feature that can help developers debug failed and flaky test runs more effectively. The ability to capture and replay test run details, including DOM, network requests, console logs, JavaScript errors, and element rendering, can greatly aid in diagnosing issues and understanding the behavior of the application during testing.

This feature could be particularly helpful in a continuous integration environment where quick and accurate debugging is essential for maintaining a reliable testing process. This enhanced visibility into the state of the application during the test run can significantly reduce debugging time and improve the accuracy of issue identification and resolution.

Let’s Configure Test Replay

To configure the Test Replay, we have to install/upgrade the new version of Cypress. After that, we have to integrate the project with Cypress Cloud.

Create a New Project and Install the Latest Version

  1. Create a Cypress Project, let’s say “cypress_testreplay_13.0.0”
  2. Cypress's latest version is installed; use the command “npm install cypress — save-dev” to install the latest version

Package.json

Package.json

Integration With Cypress Cloud

Since we need to debug the test case in the Cloud, we need to integrate our test case with Cypress Cloud.

Step 1

Open the URL.

Cypress

Step 2

Log in with any of the above options.

Step 3

In my case, I am logged in with GitHub, and the project Cypress_TestReplay is already created.

Cypress_TestReplay

Click on the above-created project Under Project Setting > Test Replay Option. We can see the Test Replay Option under the project. We can on/off this option. If we don’t want to debug using this option, just disable it.

Test Replay option

Step 4

Once you set up your project to record, generate a unique projectId for your project and automatically insert it into your Cypress configuration file.

Cypress configuration file

Or we can copy/paste the project ID from the below screen as well.

Project ID

Step 5

For demo purposes, I am taking two test cases.

Test Case 1

JavaScript
 
/// <reference types="cypress" />const username = "standard_user";
const password = "secret_sauce";

describe("Login to Saucedemo", () => {
  it("should log in with valid credentials", () => {
    cy.visit("https://www.saucedemo.com/");
    cy.get("#user-name").type(username);
    cy.get("#password").type(password);
    cy.get("#login-button").click();
    cy.get("#react-burger-menu-btn").click();
    cy.get("#logout_sidebar_link").click();
  });
});


Test Case 2

JavaScript
 
/// <reference types="cypress" />
describe('example to-do app', () => {
  beforeEach(() => {
    cy.visit('https://example.cypress.io/todo')
  })

  it('displays two todo items by default', () => {
    cy.get('.todo-list li').should('have.length', 2)
    cy.get('.todo-list li').first().should('have.text', 'Pay electric bill')
    cy.get('.todo-list li').last().should('have.text', 'Walk the dog')
  })

  it('can add new todo items', () => {
    const newItem = 'Feed the cat'
    cy.get('[data-test=new-todo]').type(`${newItem}{enter}`)
    cy.get('.todo-list li')
      .should('have.length', 3)
      .last()
      .should('have.text', newItem)
  })

  it('can check off an item as completed', () => {
    cy.contains('Pay electric bill')
      .parent()
      .find('input[type=checkbox]')
      .check()
    cy.contains('Pay electric bill')
      .parents('li')
      .should('have.class', 'completed')
  })
})


Execute the Test Cases

To execute the test case in the cloud, we have to run the below command.

npx cypress run - record - key e9x11xxxx–6dd6–xxxxx-81a3-xxxx


In the above command, we have used the  —  key that can be found under the project setting.

record keys

Let's run the above command, and we can see that all test cases are passed successfully.

success

Debug With Test Replay

Step 1: Update the Script To Fail It

Let’s change the script such that one test case fails, and then we’ll troubleshoot that test case directly in Cypress Cloud.

Let's change the length from 3 to 5 to fail the script in the below script:

JavaScript
 
it('can add new todo items', () => {
    const newItem = 'Feed the cat'
    cy.get('[data-test=new-todo]').type(`${newItem}{enter}`)
    cy.get('.todo-list li')
      .should('have.length', 5)
      .last()
      .should('have.text', newItem)
  })

run the test

Now, run the test case again. In the screenshot below, we can see test case has failed.

test has failed

Open the above-failed test case, and we can see the Test Replay button against the Failed test case.

failed test case

Step 2: Let's Debug the Script

Click on the Test Reply button on the above screen. We can see that the left side of the screen displays the command log just like in the Cypress app, where you can step through, inspect, and time travel, and debug your test.

Debug the Script

On the right side, we can see Developer Tools, which dive into network-level traffic and console events and inspect the application under test just as you can in the browser.

browser

Inspect the Element

We can inspect any of the elements in Cypress Cloud itself using the browser developer tool — the screenshot attached below displays how we can inspect the element.

browser development tool

browser developer tool2

DOM Manipulation and Network Requests

By capturing the state of the DOM and network requests, developers can better understand how the application behaved during the test run. This can be crucial for identifying issues related to dynamic content, user interactions, or AJAX requests. In the below screenshot, we can see we can easily manipulate the DOM.

We can manipulate the DOM in Cypress Cloud itself:

We can manipulate the DOM in Cypress Cloud itself

In a network call, we can check the request header and response:

In a network call, we can check the request header and response

Console Logs and Errors

Access to console logs and JavaScript errors during the test run can provide insight into what was happening within the application at different stages. This can be particularly helpful for diagnosing unexpected behavior or errors.

Conclusion

Test Replay in Cypress Cloud appears to be a feature designed to enhance the debugging process for failed or unreliable test runs within a CI/CD setup. It enables developers to accurately retrace the steps of a test run, inspect various aspects of the application’s behavior, and efficiently identify the root causes of issues.

Cloud Debug (command) Testing

Published at DZone with permission of Kailash Pathak. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Real Device Cloud Testing: All You Need to Know
  • Simplified Development With Azure DevOps
  • Developers Are Scaling Faster Than Ever: Here’s How Security Can Keep Up
  • Scaling Your Testing Efforts With Cloud-Based Testing Tools

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: