Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon 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 desk6 min

How to Handle Animations and Loading States in Visual Tests

Capture visual tests in a known state: assert meaningful readiness, control CSS and JavaScript motion deliberately, and stabilize changing resources and data.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make visual tests deterministic by capturing a known application state, not by waiting an arbitrary number of seconds. First set predictable data and interactions, then assert that the content under test is ready. For a settled-state Playwright screenshot, use its animation control; handle app-driven JavaScript motion separately. Use fixed delays only when no observable completion signal is available.

What makes a visual test stable?

A screenshot is a sample of the UI at one moment. For a useful visual test, that moment must represent the state the test is intended to protect. The page should have deterministic data and interactions, relevant content should be ready, and motion should either be deliberately settled or deliberately tested.

As an Amazon Associate I earn from qualifying purchases.

There is no single browser event that proves every application update and future resource request is finished. Network inactivity can be a useful clue, but asynchronously requested resources may arrive afterward. Assert a meaningful condition in the page instead of treating a generic load signal as proof of readiness. Chromatic’s resource-loading guidance describes this limitation and its approach to waiting for images, fonts, and network inactivity.

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

Use Playwright’s screenshot assertion for settled-state checks

Playwright’s toHaveScreenshot() waits for two consecutive page screenshots to match, then compares the last screenshot with the expected image. Its documented animations default is "disabled". See the Playwright PageAssertions API. Check the API documentation for the Playwright version installed in your project, since defaults can vary between versions.

#1 Best Overall

Here is a complete example for a page whose contract is its settled appearance. The readiness assertion targets a page-specific signal; replace the selector and expected text with ones that mean the relevant content is ready in your application.

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

test('account page matches its settled visual state', async ({ page }) => {
  await page.goto('http://localhost:3000/account');

  // Wait for meaningful content, not just a generic page-load event.
  await expect(page.getByRole('heading', { name: 'Your account' })).toBeVisible();
  await expect(page.getByTestId('account-summary')).toContainText('Current plan');

  await expect(page).toHaveScreenshot('account.png', {
    animations: 'disabled',
  });
});

What disabling animations does

For finite CSS and Web Animations, Playwright fast-forwards the animation to completion so its completion event can fire. Infinite animations are canceled to their initial state for the capture and played again afterward. Those behaviors may affect the captured UI: decide whether the test should protect the final state, the initial state, or a frame while motion is in progress.

Disabling motion is suitable when the intended contract is the settled layout and appearance. It is not a substitute for testing animation behavior: if timing, transitions, or an animated state matters, allow motion and assert an intentional state or frame through an application-level control.

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

Handle JavaScript-controlled motion separately

Browser screenshot controls do not settle every animation an application can run. Code driven by requestAnimationFrame or a JavaScript animation library may continue changing the page even when CSS and Web Animations are disabled. Chromatic likewise documents that it pauses CSS transitions, CSS and SVG animations, and videos, but JavaScript-driven animations may need to be paused by the test or allowed to finish. See Chromatic’s animation guidance.

Prefer an explicit test hook

  • Expose a deterministic animation mode, pause control, or completion signal that the test can use.
  • Where practical, control the clock or animation state so the test can capture the same deliberate point every run.
  • If the animation is part of the behavior being tested, assert its intended state rather than suppressing it.

If the application has no reliable completion signal or controllable state, a short delay can be a fallback. Choose it based on observed behavior in the test environment, not as a universal settling rule. Delays can make tests slower while still failing to cover slower or differently scheduled work.

Wait for the content that matters

Make readiness assertions specific to the screenshot’s purpose. A page’s initial render may precede a data response, lazy-loaded image, font swap, or update triggered by later interaction. Assert the relevant content, image, or application state before capturing; if a request starts after initial rendering, ensure the test covers the state that depends on it.

Make fonts and images dependable

  • Prefer local or otherwise controlled assets when an external host would make availability or timing unpredictable.
  • Assert that important images or their surrounding content are present before the screenshot.
  • Account for fonts that load late and change text wrapping, widths, or vertical layout.
  • Avoid relying on network inactivity alone: it is a heuristic, not proof that all future asynchronous work is complete.

Late fonts or images and slow rendering are documented causes of unstable snapshots. Chromatic’s snapshot documentation explains its snapshot workflow, while its unstable-test guidance discusses diagnosing inconsistent results.

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

Control dynamic data; mask only what is irrelevant

Fix dates, random values, user data, and other changing inputs when they are not the subject of the test. A changing region that is genuinely outside the visual contract can be masked using the visual testing tool’s supported mechanism. But if its appearance or content matters, control its data or state instead of hiding it: a mask can conceal a real regression.

Playwright’s screenshot assertion also supports masking locators. For example, this is appropriate only when the timestamp is intentionally excluded from the assertion:

await expect(page).toHaveScreenshot('account.png', {
  animations: 'disabled',
  mask: [page.getByTestId('live-timestamp')],
});

Choose a local assertion or hosted visual workflow

Playwright’s native assertion is a direct fit when tests should compare screenshots against expected images as part of the existing test run. A hosted visual testing workflow such as Chromatic may suit teams that want hosted snapshots and review. Evaluate both against how they handle animation, readiness, control of changing data and resources, and review needs; the cited documentation does not establish a universal best product, comparative price, or guaranteed stability rate.

Chromatic for Playwright documents its Playwright workflow. Whichever approach you use, the screenshot is only meaningful when it captures the intended state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a one-off website screenshot rather than a visual regression assertion, ScreenshotNeo offers a screenshot API and an MCP server for developers. This GET request returns an image for the supplied URL:

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

See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. These captures do not replace deterministic visual assertions in a test suite.

Sign up for 1,000 free screenshots a month with no card.

Troubleshoot unstable screenshots

  • The screenshot changes between runs: Inspect the test trace, console output, network activity, and captured DOM or state to find the changing input before adding delays or widening diff thresholds.
  • A CSS transition still affects the result: For a settled-state Playwright assertion, confirm that animations: 'disabled' is set and that the test expects the final state. If the transition itself is under test, do not disable it.
  • A JavaScript animation keeps moving: Add an application-level pause or completion hook, or assert a deliberate animation state. Playwright’s screenshot setting does not automatically settle all app-specific motion.
  • Text wraps differently: Check whether the intended font has loaded and use controlled font resources where practical.
  • An image or content appears after the screenshot: Assert the relevant image or application content directly and account for requests that begin after initial render; generic network quiet cannot predict every future request.
  • A delay seems to fix a failure inconsistently: Find the underlying state or resource variation. A delay is a fallback, not evidence that the page is reliably ready.
  • A mask makes tests pass but hides changes: Remove it for content that belongs to the visual contract; stabilize the data or state instead.

FAQ

Should I disable animations in every visual test?

No. Disable them when the intended assertion is a settled appearance. Keep motion under test when animation timing or behavior is part of what the test must protect.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Does network idle mean the page is fully ready?

No. It describes a period without observed network activity, but cannot guarantee that later asynchronous requests or application updates will not occur. Assert the meaningful ready state for the screenshot.

Can a hosted screenshot replace a visual regression test?

A screenshot capture gives you an image; regression testing also requires a defined expected state and a comparison or review process. Choose the workflow that supplies the controls and review your team needs.

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.

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.