DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

How to Fix Playwright Screenshot Tests That Fail Because of Timestamps

Use Playwright’s clock to make tested timestamps deterministic, mask incidental time, and inspect diffs and rendering environments when failures persist.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the page’s time deterministic if the timestamp is part of the behavior you are testing; otherwise, mask or hide the changing region in the screenshot assertion. For a fixed displayed date while page timers keep running, call page.clock.setFixedTime() before navigating. If timers themselves need controlled progression, install Playwright’s clock before navigation.

Choose the fix based on what the test should verify

Test requirement Approach
The displayed date or time matters, but timers should continue normally Use page.clock.setFixedTime() before page.goto().
Countdowns, scheduled updates, or timeout-driven UI must run on a controlled timeline Use page.clock.install() before navigation, then pause or advance time as needed.
The timestamp is incidental and should not be checked visually Mask its locator in the screenshot assertion or hide it with screenshot-only CSS.
The timestamp is stable, but screenshots still differ Inspect the screenshot diff and check whether browser and host environments match the baseline environment.

Freeze the displayed date with setFixedTime()

For a test that needs one deliberate, stable date while ordinary timers continue running, set the clock before loading the page:

As an Amazon Associate I earn from qualifying purchases.

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

test('renders a stable timestamp', async ({ page }) => {
  await page.clock.setFixedTime(new Date('2024-02-02T10:00:00'));
  await page.goto('http://localhost:3000');
  await expect(page).toHaveScreenshot();
});

Choose a date whose displayed output is intentional. The order matters: set the time before navigation so the page sees it while loading. If the application formats dates according to locale or timezone, keep those test inputs consistent too; the clock alone does not establish how a particular application configures them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control timer progression with install()

Use page.clock.install() when the test concerns behavior driven by timers, such as countdowns, scheduled updates, or timeouts. Install the clock before navigation. Playwright’s guide recommends initializing slightly before the intended test time so page-load timers can run normally; after loading, use the clock methods to pause or advance time as the scenario requires.

Avoid mixing clock-related calls in the wrong order: the guide warns that calling install() after other clock-related calls can lead to undefined behavior. For a simple fixed current date with timers continuing, prefer setFixedTime(). Playwright describes setSystemTime() as an advanced option: it changes system time without triggering timers. Use it only when that distinction matches the scenario you need to test.

Exclude timestamps that are not part of the visual test

If the assertion should ignore a changing timestamp, pass its locator in toHaveScreenshot({ mask: [...] }). A mask covers the element’s bounding box, so use it only when that area is intentionally outside the visual assertion.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Alternatively, use screenshot-only CSS through stylePath to hide the timestamp or other volatile content during capture. This preserves the live page while changing what the screenshot assertion sees. Choose masking or hiding only when the timestamp itself is not behavior under test; otherwise, a stable clock is the more meaningful fix.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Diagnose a failure that remains

Check the screenshot diff before changing a baseline

toHaveScreenshot() waits for two consecutive page screenshots to match before comparing against the stored expectation. That can help with unstable captures, but it does not make an application timestamp constant. Review the actual image, expected image, and diff to see whether the time, another page element, or rendering differences caused the mismatch.

Playwright’s Trace Viewer can show screenshot diffs, actual and expected images, action details, and logs. Use that evidence to locate the divergence. Update snapshots with --update-snapshots only after confirming that the visual change is intended.

Keep the rendering environment consistent

Browser rendering can vary with the host operating system, browser version, settings, hardware, power source, and headless mode. Generate and compare baselines in the same environment; where needed, keep browser- or platform-specific baselines. Playwright’s Visual comparisons guidance says: “For consistent screenshots, run tests in the same environment where the baseline screenshots were generated.”

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Check where the displayed value comes from

If the date remains unexpected after setting the browser clock, inspect the test’s ordering, the timestamp source, and the diff. A browser clock setting controls browser time APIs; it does not by itself establish how a particular application obtains or formats its displayed value. The appropriate fix depends on the application and test setup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common failure modes and fixes

  • Clock is set after navigation: set it before page.goto(), so the page loads with the intended time.
  • Timers stop or behave differently than expected: use setFixedTime() when timers should continue, and reserve install() for controlled timer progression.
  • install() behaves unpredictably: install before navigation and before other clock-related calls.
  • Masked screenshot hides content you meant to test: mask only the timestamp’s region, and remove the mask if that visual behavior matters.
  • Fresh snapshots still differ across machines: compare browser and host settings with the baseline environment, then inspect the actual/expected diff in Trace Viewer.
  • A new baseline seems to fix the failure: first confirm the change is intended; updating snapshots can otherwise conceal a real regression.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot artifact of a public page rather than a deterministic Playwright test and stored baseline, ScreenshotNeo can return an image with one GET request. It does not replace Playwright’s clock controls or visual assertions.

For example, save a page screenshot as WebP with cURL (see the ScreenshotNeo API documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Cookie banners, popups, and chat widgets are removed before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for free and try ScreenshotNeo.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.