Prompt

How do I capture screenshots and logs when a synthetic test fails?

Technology / Observability2 observationsLast seen Nov 16, 2026

Latest observation

Nov 16, 2026OpenAI APIWeb search: off

To capture screenshots and logs on synthetic test failure, the exact approach depends on the tooling you’re using, but the general pattern is:

  1. Detect failure in the test step
  2. On failure, capture evidence
    • screenshot
    • browser console logs
    • network logs / HAR
    • page source or DOM snapshot
  3. Attach or save the artifacts
  4. Upload/store them where your CI or monitoring system can collect them

Common ways to do it

If you’re using Playwright

Use testInfo.attach() and failure hooks:

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

test.afterEach(async ({ page }, testInfo) => {
  if (testInfo.status !== testInfo.expectedStatus) {
    await testInfo.attach('screenshot', {
      path: await page.screenshot({ path: `artifacts/${testInfo.title}.png`, fullPage: true }),
      contentType: 'image/png',
    });

    const logs = [];
    page.on('console', msg => logs.push(`${msg.type()}: ${msg.text()}`));
    await testInfo.attach('console-logs', {
      body: logs.join('\n'),
      contentType: 'text/plain',
    });
  }
});

Also enable built-in screenshot/video/trace recording:

use: {
  screenshot: 'only-on-failure',
  trace: 'on-first-retry',
  video: 'retain-on-failure',
}

If you’re using Selenium

Wrap your assertions in a try/catch, then:

  • take a screenshot with getScreenshotAs()
  • collect browser console logs if supported
  • save page source

Example:

try {
    // test steps
} catch (Exception e) {
    File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenshot, new File("artifacts/failure.png"));

    String source = driver.getPageSource();
    Files.writeString(Path.of("artifacts/page-source.html"), source);

    throw e;
}

For browser logs:

LogEntries logs = driver.manage().logs().get(LogType.BROWSER);

If you’re using Cypress

Use afterEach() or the screenshotOnRunFailure setting:

describe('test', () => {
  afterEach(function () {
    if (this.currentTest.state === 'failed') {
      cy.screenshot();
    }
  });
});

Console logs can be captured by stubbing console or using Cypress event hooks.

For synthetic monitoring platforms

Many platforms already support this:

  • Datadog Synthetics: screenshots, step logs, HAR, and browser logs can be included automatically on failure
  • New Relic Synthetics
  • Pingdom / Checkly / Grafana Synthetic Monitoring

Usually you need to:

  • enable failure artifacts in the monitor settings
  • make sure the test runner is configured to store them
  • attach custom logs if your platform supports it

Best practices

  • Capture artifacts only on failure to reduce noise/storage
  • Save artifacts with a timestamp / test name / run ID
  • Include:
    • screenshot
    • console logs
    • network/HAR
    • DOM snapshot
    • URL and timing info
  • Upload to a shared location like S3, CI artifacts, or your observability tool

If you tell me which framework or synthetic monitoring tool you’re using, I can give you the exact code/config for that setup.

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.