Prompt

How do I capture screenshots and videos on test failures

Technology / Testing & QA2 observationsLast seen Oct 27, 2026

Latest observation

Oct 27, 2026OpenAI APIWeb search: off

You usually do this in your test framework by adding a “failure hook” that:

  1. detects when a test fails
  2. captures a screenshot and/or video
  3. attaches the artifact to the test report or saves it to disk

The exact setup depends on the tool you’re using. Here are the common patterns.


Cypress

Screenshots

Cypress can automatically take screenshots on failure if configured:

// cypress.config.js
module.exports = {
  screenshotOnRunFailure: true,
  video: true,
}

Videos

Cypress records video for the whole spec run when video: true is enabled.

Tips

  • Screenshots are saved in cypress/screenshots
  • Videos are saved in cypress/videos
  • You can also manually call cy.screenshot() in a failing test or hook

Playwright

Playwright can capture screenshots and video automatically for failing tests.

Configure in playwright.config.ts

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },
});

Behavior

  • screenshot: 'only-on-failure' saves a screenshot only when the test fails
  • video: 'retain-on-failure' keeps the recording only for failed tests

Selenium / WebDriver

You typically do this manually in your test framework after a failure.

Example idea

  • In an afterEach / teardown hook, check if the test failed
  • If so, call the driver’s screenshot API and save the image

Java example

if (testFailed) {
    File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    Files.copy(src.toPath(), Paths.get("screenshots/failure.png"));
}

Videos

Selenium itself does not provide video recording.
You’d usually use:

  • a cloud grid provider with video recording, or
  • a separate screen-recording tool in CI

Jest / Mocha / Puppeteer

Screenshots

Take a screenshot in a failure handler or catch block.

afterEach(async () => {
  if (expect.getState().currentTestName && testFailed) {
    await page.screenshot({ path: `screenshots/${Date.now()}.png` });
  }
});

Videos

Puppeteer does not have built-in simple test video capture; people usually use:

  • CI screen recording
  • Docker/Xvfb recording
  • a cloud browser service

General approach

If your framework doesn’t support this out of the box:

  1. Add a teardown hook
    • afterEach, afterTest, onTestFailure, etc.
  2. Detect failure
    • framework-specific test status or exception
  3. Capture screenshot
    • using the browser driver API
  4. Capture video
    • either built-in framework support or external recording
  5. Store artifacts
    • save locally, upload to CI artifacts, or attach to test reports

Best practice

  • Save artifacts with the test name and timestamp
  • Keep only failure artifacts to avoid huge storage use
  • Upload screenshots/videos in CI so they’re easy to inspect
  • If possible, include logs and DOM snapshots too

If you tell me which framework you’re using — for example Cypress, Playwright, Selenium, Appium, Jest, or Robot Framework — I can give you the exact code/config for screenshots and videos on failure.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.