Screenshots and Videos in Cypress
Last Updated :
23 Jul, 2025
Cypress is a very popular testing framework used for testing web applications. In Cypress, developers can write code for test cases in JavaScript, which is most common among developers. Cypress provides various features, but Screenshots and videos are features that are easy to implement. This feature helps the tester to easily debug and understand test failures.
What are Cypress Screenshots?
Cypress Screenshots are the feature that automatically captures images of our application at different stages of your test execution. These screenshots can be taken. When a test fails at specific points in your tests where you want to capture the application's state, you can explicitly take screenshots. When a test fails, these images serve as a visual record of the application's appearance at that moment, aiding in the swift diagnosis and resolution of issues View them to understand the application's state during test execution.
How do you Capture Screenshots Explicitly during a Test Run in Cypress?
We can capture screenshots at any step or time, without depending on cypress for capturing the test upon failure of test. For this, the tester specifies with command that at this point take screenshots, this can be achieved by command cy.screenshot at any point.
To capture screenshots explicitly during a test, write this command in the test step at which you want to take screenshots.
JavaScript
cy.screenshot('Custom name')
Example of Taking Screenshots explicitly:
JavaScript
describe('My first Test suite',function(){
it('ViewPort Test',function(){
cy.visit('https://write.geeksforgeeks.org/')
cy.screenshot('homepage')
cy.wait(2000)
})
it('Tc-1 ViewPort Test',function(){
cy.viewport(990,760)
cy.visit('https://write.geeksforgeeks.org/')
//this is first point where we want to take screenshot
cy.screenshot('homepage')
cy.wait(1500)
})
it('Tc-2 ViewPort Test',function(){
cy.viewport(800,600)
cy.visit('https://write.geeksforgeeks.org/')
//this is Second point where we want to take screenshot
cy.screenshot('homepage')
cy.wait(1500)
})
it('Tc-3 ViewPort Test',function(){
cy.viewport(600,500)
cy.visit('https://write.geeksforgeeks.org/')
//this is third point where we want to take screenshot
cy.screenshot('homepage')
cy.wait(1500)
})
})
Output:
Output of view port testingDifferent Naming Conventions Used for Screenshots in Cypress
Naming Conventions in cypress are used for naming screenshots, Videos and other files. this naming conventions help to enhance the readability and clarity of the test in cypress. these naming conventions are of Different types like, Default Naming, Custom Naming, With Prefix Naming,
1. Default Naming: When we don't specify any name to the screenshot, Cypress generates name automatically based on the test suite, test case names and viewport-Size.
Format:
JavaScript
cypress/screenshots/[test-file-path]/[test-name] ([viewport-size]).png
Example:
cypress/screenshots/login.spec.js/User Login Test (1280x720).png
2. Custom Naming: We can assign a custom name to the screenshot using this command, Custom names are the names that is assigned by a tester for easy identification.
Format:
JavaScript
cypress/screenshots/[custom-name].png
Example:
cy.screenshot('custom-login-page')
saves as,
cypress/screenshots/custom-login-page.png.
3. Dynamic Naming Based on Context: In this naming conventions there are two components of name one is variables and the other is context, these two components are used to generate dynamic and meaningful names.
Format:
JavaScript
[context-based-name]-[timestamp].png
Example:
cy.screenshot(Login-${Date.now()})
saves as
Login-1627874523000.png.
4. Using File Path Naming: In this type of naming the relative path of file is included in the file name for storing file in different directories.
Format:
JavaScript
cypress/screenshots/[relative-path]/[custom-name].png
Example:
cy.screenshot('screenshots/login/custom-login')
saves as
cypress/screenshots/screenshots/login/custom-login.png.
5. With Prefix: We can also use the blackout option which hides the sensitive information before taking screenshots command.
JavaScript
cy.screenshot('custom-name', { blackout: ['selector'] });
6. Multiple Screenshots: Cypress automatically appends a number to the screenshot name if you take multiple screenshots with the same name within the same test run, e.g., custom-name.png, custom-name-1.png, etc.
How do we get Automatic Screenshots of Test Failures in Cypress?
Automatic screenshots of test failures in cypress are enabled by default. This helps in capturing visuals to analyze why test failed at any instant. When a test fails it will capture automatically screenshots and save this screenshot in screenshots folder with name tag 'randomTest(failed).png'. Cypress automatically captures screenshots on the failure of test. for manually enabling this feature by enabling screenshotOnRunFailure option in file cypress.config.js/cypress.json.
Add the following code to your cypress.config.js/cypress.json:
JavaScript
{
screenshotOnRunFailure: true,
}
With this configuration, Cypress will automatically capture screenshots whenever a test fails and save them in the specified screenshots Folder.
Output:
Failed test automatic screenshot.We can view failure test screenshots in the file named screenshots. The naming convention for failure screenshots typically includes the test suite name, test case name, and a timestamp to help identify them easily.
What are Cypress Videos?
Cypress Videos is a feature that records a video of your entire test run. This video captures everything that happens in the browser, providing a complete visual log of the test execution. by this feature we can record the whole test process and we can review it. This automatic video recording feature is used for Debugging test failures, Understanding complex interactions and for sharing the test results with team members
How we Can Capture Video of complete test Automatically?
Step1: Write this code in file: "Cypress.config.js" and save it.
JavaScript
const { defineConfig } = require("cypress");
module.exports = defineConfig({
video: true,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
Step 2: Write this on terminal of Cypress
JavaScript
It will automatically start running all tests in your file and captures videos, automatically create a video file and store all videos in it.
Output:
recorded Video locationHow to Upload and Verify Screenshots, Videos on Cypress Dashboard?
First of all, we have setup the cloud dashboard and link this dashboard with project after that all videos and screenshots can be uploaded and viewed on the cloud-hosted Cypress Dashboard after that for uploading videos and screenshots on cloud we use this command "--record" flag with the key of the project, and it will automatically upload all the screenshots and videos to the Project Dashboard. So, you can just run the below command to upload the screenshots and videos to the Cypress Dashboard.
JavaScript
npx cypress run --record --key "d1902b21-dad8-4e12-8aa1-cddd1a4e320e"
Step 1: Open cypress and click on connect your project.
Cypress dashboardStep2: Choose the visibility of your project either public or private its up to you. After that, click on create project.
After clicking connect, choose private or public accessStep3: A unique key will be assigned to project. Copy this command and run in terminal of your vs code in which cypress file is stored.
Copy your project keyStep4: Click on the test that you performed.
Cypress cloud DashboardStep5: after clicking it shows failed test and passed test with check and cross.
Test pass or failed detailsStep6: When we click on the failed test it shows detailed report of test. After that, click on Test replay in bottom.
complete test details, click on test replay to watch recorded video.Step7: So, now we can review your test by playing videos or screenshots.
Uploading and Verifying the screenshots and videos on Cypress DashboardConclusion
Cypress's screenshot and video features are powerful tools for enhancing the test debugging process. Screenshots capture the application's state at specific points, while videos provide a comprehensive visual log of the test execution. These features help developers quickly identify and resolve issues, ensuring that web applications function as expected
JavaScript
{
"screenshotsFolder": "my-screenshots",
"videosFolder": "my-videos"
}
How do I capture a screenshot with obscured elements?
Use the blackout option with the cy.screenshot() command to obscure specific elements before capturing the screenshot.
JavaScript
cy.screenshot('screenshot-name', { blackout: ['#element1', '.element2'] });
How can we disable video recording for specific test runs?
we can disable video recording for specific test runs by setting the video option to false in the cypress.json configuration file.
Similar Reads
Software Testing Tutorial Software testing is an important part of the software development lifecycle that involves verifying and validating whether a software application works as expected. It ensures reliable, correct, secure, and high-performing software across web, mobile applications, cloud, and CI/CD pipelines in DevOp
10 min read
What is Software Testing? Software testing is an important process in the Software Development Lifecycle(SDLC). It involves verifying and validating that a Software Application is free of bugs, meets the technical requirements set by its Design and Development, and satisfies user requirements efficiently and effectively.Here
11 min read
Principles of Software testing - Software Testing Software testing is an important aspect of software development, ensuring that applications function correctly and meet user expectations. From test planning to execution, analysis and understanding these principles help testers in creating a more structured and focused approach to software testing,
3 min read
Software Development Life Cycle (SDLC) Software Development Life Cycle (SDLC) is a structured process that is used to design, develop, and test high-quality software. SDLC, or software development life cycle, is a methodology that defines the entire procedure of software development step-by-step. The goal of the SDLC life cycle model is
8 min read
Software Testing Life Cycle (STLC) The Software Testing Life Cycle (STLC) is a process that verifies whether the Software Quality meets the expectations or not. STLC is an important process that provides a simple approach to testing through the step-by-step process, which we are discussing here. Software Testing Life Cycle (STLC) is
7 min read
Types of Software Testing Software testing is a important aspect of software development life-cycle that ensures a product works correctly, meets user expectations, and is free of bugs. There are different types of software testing, each designed to validate specific aspects of an application, such as functionality, performa
15+ min read
Levels of Software Testing Software Testing is an important part of the Software Development Life Cycle which is help to verify the product is working as expected or not. In SDLC, we used different levels of testing to find bugs and errors. Here we are learning those Levels of Testing in detail.Table of ContentWhat Are the Le
4 min read
Test Maturity Model - Software Testing The Test Maturity Model (TMM) in software testing is a framework for assessing the software testing process to improve it. It is based on the Capability Maturity Model(CMM). It was first produced by the Illinois Institute of Technology to assess the maturity of the test processes and to provide targ
8 min read
SDLC MODELS
TYPES OF TESTING