How to Capture Screenshots and Videos Using Playwright
On This Page What are Visual Artifacts in Test Automation (Screenshots vs Videos)
A failing test can find like a beat end when there & # 8217; s nothing optic to explain what really happened on the screen. Take a familiar scenario: a UI test betray in CI, yet the same test passes flawlessly on your machine. No logs point to the issue. The study simply says a button wasn & # 8217; t clicked in time. Maybe an animation briefly continue it. Maybe the page scrolled at the wrong moment. Maybe a modal flashed and disappeared before the next stride fired. Without visual proof, the movement remains guesswork. This is where screenshots and picture in Playwright become essential. They show exactly what the browser saw-turning invisible failures into clear, actionable evidence. A individual screenshot shows the accurate state of the page at failure. A picture disclose the full sequence-every transition, delay, and unexpected transmutation. Points to note While capturing Screenshots & amp; Videos in Playwright This guide explain how to capture screenshots and record video in, and best practices to follow while implementing these. Screenshotsare unchanging picture of the browser state at a specific moment, whilevideosrecord the executing stream of a examination. Screenshotsare idealistic for pinpointing UI mismatches & # 8211; e.g., layout shifts, incorrect styles & # 8211; whereasvideosseizure dynamical interaction such as animations, transitions or unexpected user flow. Using them together give a fuller picture of what happens during test execution, aiding root-cause analysis. Read More: Capturing visual artifacts in Playwright enhances several aspects of test mechanization: Read More: Learn how screenshots and videos in Playwright are captured during test executing. Installing Playwright and creating a basic test Begin by installing Playwright in your undertaking: Then create a bare test file, for example example.spec.ts: Configuring screenshot and video options inplaywright.config.ts In playwright.config.ts, enable screenshots/videos globally or per-project: The official docs line that video show fashion include& # 8216; off & # 8217;, & # 8216; on & # 8217;, & # 8216; retain-on-failure & # 8217;, and & # 8216; on-first-retry & # 8217;. These configuration scene establish a baseline for capturing visual artefact without whelm your storage or workflow. is a cloud-based testing creature, that streamline the setup phase by providing ready-to-use existent browsers and devices, decimate the demand to configure or sustain local environments. With instant cloud approach, detailed logs, videos, and network data captured automatically, it ensures every test starts with consistent conditions and dependable visual artifact, without handling browser updates or device setup. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Capturing screenshots in Playwright gives a open snapshot of the browser & # 8217; s state at any moment, help name UI issues with precision. Here are the steps to follow: The nucleus method for fascinate screenshots: You can optionally specify options such as format or calibre. Full-page: Element: Buffer-capture (in-memory): Using config to enchant only on failures (or on first retry) restrict disturbance and focuses artifacts on problematic footrace. This strategy helps maintain doable disk usage and meaningful outputs for analysis. Read More: Recording videos in Playwright furnish a uninterrupted view of each examination run, making it easy to trace interaction, place timing issues, and understand failures end-to-end. Video capture is endorse via the video option in config or via recordVideo in context creation: Or during context: After the browser context is closed, video files are prevail. You can find the way: Recording videos of every test can be heavy on storage. Recommended practices: Read More: Integrating screenshots and videos into the test pipeline guarantee every run produces actionable ocular grounds, strengthening debugging and transparency across squad. Using screenshots/videos for debugging and bug reports When a test fails, part the screenshot or picture along with logs. Visual evidence provides context that logs alone may miss. Example: layout shift occurs only after a hover interaction, seeable in the video. Incorporating into CI/CD workflows Configure your CI to archive screenshots/videos as artifact when a run completes. This provides a historical record of trial results and facilitate when tracing regressions backwards across runs. Visual regression testing with screenshots/videos With screenshot functionality, use assertions like: This enables compare of current UI state with a baseline. Storing videos enables reviewing interaction between trial and spotting UI behaviour shifts. Troubleshooting screenshot and picture issues in Playwright involves identifying why artifacts fail to save, grow too bombastic, or impact performance, and applying targeted fixes to keep capture authentic. Read More: Following best practices for screenshots and video in Playwright helps keep consistent output, control storage use, and check optical artifacts remain accurate and useful across environments. is a cloud-based examination tool that reinforces better practices by escape Playwright trial on stable, managed infrastructure that maintain screenshots and videos consistent across browsers and device. High-scale parallel execution zip up visual proof, while the unified debugging dashboard organizes artefact for quick reexamination. With built-in logs, videos, and seamless CI/CD integration, squad can optimize capture workflow without worrying about maintenance or cross-browser reliability. Testing screenshots and videos at scale requires reliable environs, predictable rendering, and consistent artifact storage. Local setups much introduce variations-different GPU drivers, mismatched browser versions, precarious network, or rendering quirks that look solely at scale. BrowserStack removes these variables by providing managed environments with real device, consistent browser configurations, scalable infrastructure, deep debugging tools, and a layer that keep Playwright & # 8217; s screenshots and picture stable and reproducible across tally. is a cloud-based examination puppet that strengthen Playwright & # 8217; s screenshot and video workflow through multiple layers of support. Here & # 8217; s how it improve truth, coverage, and debug efficiency: Capturing screenshots and picture with Playwright transforms visual testing from a manual afterthought into an integral constituent of the automation flow. When used strategically-configured for key flows, combine with CI/CD pipelines, and optionally scaled via -it raises the transparency, diagnosability and dependableness of web trial suites. On This Page # Ask-and-Contributeabout this matter with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How To Capture Screenshots & # 038; Videos utilise Playwright
Overview
What are Visual Artifacts in Test Automation (Screenshots vs Videos)
Why Capture Screenshots and Videos in Playwright?
Setup and Configuration for Capture Screenshots and Videos in Playwright
npm install -D @ playwright/test npx playwright install
importee {trial, look} from & # 8216; @ playwright/test & # 8217;; trial (& # 8216; basic examination & # 8217;, async ({page}) = & gt; {
await page.goto (& # 8216; https: //example.com & # 8217;);
await expect (page) .toHaveTitle (/Example/);
});import {defineConfig} from & # 8216; @ playwright/test & # 8217;; export default defineConfig ({
use: {
screenshot: & # 8216; only-on-failure & # 8217;, // capture screenshot when tryout fails
video: {mode: & # 8216; retain-on-failure & # 8217;} // record video only when test fails
},
});Capturing Screenshots with Playwright
Basic screenshot API usage (page.screenshot)
await page.screenshot ({path: & # 8216; screenshot.png & # 8217;});Full-page, viewport, element-level, and buffer captures
await page.screenshot ({path: & # 8216; fullpage.png & # 8217;, fullPage: true});await page.locator (& # 8216; .header & # 8217;) .screenshot ({path: & # 8216; header.png & # 8217;});const pilot = await page.screenshot (); console.log (buffer.toString (& # 8216; base64 & # 8217;));
Screenshot on failures or retries
Recording Videos with Playwright
Configuring picture recording (video way, size, directory)
exportation default defineConfig ({use: {
video: {mode: & # 8216; on-first-retry & # 8217;, size: {width: 640, height: 480}}
},
});const context = await browser.newContext ({recordVideo: {dir: & # 8216; videos/ & # 8217;, size: {width: 640, height: 480}}
});Accessing and saving enter video file
const videoPath = await page.video () .path ();
When and what to show?
Integrating Visual Captures into Your Test Pipeline
await expect (page) .toHaveScreenshot (& # 8216; landing.png & # 8217;);
Troubleshooting Common Issues in Capturing Screenshots and Videos in Playwright
Best Practices and Optimization Tips for Capturing Screenshots/Videos in Playwright
How BrowserStack helps in Testing Screenshots/Videos in Playwright?
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously