UI Testing Beyond Screenshots: What Are You Missing?
A UI test can pass, every button can work, and every API call can return the expected response. Yet the page can still look wrong. A button might sit 4 pixels too low. A heading might use the wrong font size. A card could have unexpected margins, or a responsive layout might break when the […]

A UI test can pass, every button can work, and every API call can return the expected response. Yet the page can still look wrong.
A button might sit 4 pixels too low. A heading might use the wrong font size. A card could have unexpected margins, or a responsive layout might break when the viewport gets narrower.
These aren’t necessarily functional bugs. They’re UI quality problems, and screenshot-only testing doesn’t always explain what’s causing them.
UI testing beyond screenshots means validating not just how a page looks, but also the DOM structure, computed CSS properties, element dimensions, alignment, and behavior across viewport sizes.
Visual regression testing remains useful. But when a test detects a difference, engineers need more than a red comparison image. They need to understand what changed, where it changed, and whether the change is actually a defect.
What Is UI Testing Beyond Screenshots?
UI testing beyond screenshots combines visual comparison with DOM inspection, CSS validation, layout measurements, and responsive behavior checks.
Instead of asking only, “Does this screenshot match the baseline?”, it asks several more useful questions:
- Is the correct element rendered?
- Does it have the expected dimensions and position?
- Are its font size, margins, padding, and alignment correct?
- Does it remain usable at different viewport sizes?
- Is the difference intentional, or did a recent code change introduce a regression?
Consider a login page. A screenshot comparison might flag a difference around the submit button. Inspecting the DOM and computed styles could reveal that a CSS change increased the button’s bottom margin from 12px to 16px.
The screenshot tells you where the page differs. DOM and CSS inspection help explain why it differs.
Why Screenshot-Only UI Testing Has Limitations
Screenshot testing is valuable because it captures the rendered result of a page. Tools such as Playwright can compare a new screenshot against a stored baseline and identify visual differences. Playwright’s visual comparison documentation explains how this works.
The problem starts when we treat image comparison as a complete UI testing strategy.
1. A visual difference doesn’t explain its cause
Suppose a checkout button appears lower than expected.
The cause could be:
- An unexpected margin on the button.
- Additional padding on its parent container.
- A different font causing the text to wrap.
- A sibling element becoming taller.
- A flexbox or grid alignment change.
A screenshot highlights the affected area, but it doesn’t directly identify which CSS rule caused the change.
Without further investigation, engineers may spend more time debugging the symptom than fixing the actual problem.
2. Small spacing differences can be easy to miss
Imagine a design system specifies 16px between a heading and a form field. A regression changes that spacing to 20px.
A human reviewer might not notice the difference immediately, especially on a large page with many components. A screenshot comparison may detect it, depending on the affected pixels and configured thresholds, but it won’t tell you whether the spacing violates the design specification.
The same applies to:
- A 4px difference between buttons.
- An unexpected 8px margin on a card.
- A label that is slightly misaligned with its input.
- A font size that differs from the design system.
These details can make an interface feel inconsistent even when individual components still work correctly.
3. One screenshot cannot cover responsive behavior
A page can look correct at a desktop viewport and fail at a smaller width.
For example, a navigation bar might overflow, a card might become wider than its container, or a primary button might be pushed below an overlapping element.
Responsive behavior needs to be checked at multiple viewport sizes and, where relevant, with different content lengths and text scaling.
Accessibility is part of this picture, too. WCAG 2.1 Success Criterion 1.4.10 addresses reflow at a width equivalent to 320 CSS pixels for vertically scrolling content, subject to its stated exceptions. W3C’s reflow guidance provides the details.
A desktop screenshot alone cannot establish that a layout meets this requirement.
4. Screenshot comparisons can be noisy
Visual regression tests can produce differences caused by:
- Font rendering.
- Browser or operating-system differences.
- Animation timing.
- Dynamic content, such as timestamps.
- Carelessly chosen screenshot capture points.
Playwright specifically recommends keeping the rendering environment consistent when generating and comparing visual baselines. Official documentation
This doesn’t make screenshot testing unreliable. It means the test environment and comparison rules need to be designed carefully.
5. A screenshot doesn’t validate the underlying UI contract
Two elements can look almost identical while having different DOM structures or computed properties.
For example, a button might look correct but lack an accessible name, or a clickable element might not behave like a real button when using a keyboard.
These problems may not be visible in a screenshot at all.
This is why visual testing should work alongside functional, semantic, accessibility, and layout checks rather than replace them.
The Better Approach: DOM + CSS + Visual Inspection
A practical UI testing strategy uses three complementary layers.
Layer 1: DOM inspection
The Document Object Model (DOM) represents the page as a tree of elements and their relationships.
DOM inspection helps you verify:
- Whether the expected element exists.
- Whether the correct element type is used.
- Whether labels, attributes, and text are correct.
- Whether an element is nested in the expected container.
- Whether the element is visible and interactable.
For example, a test can verify that the checkout action is an actual button with the expected accessible name instead of merely checking that a rectangle resembling a button appears in a screenshot.
DOM checks are useful for structural and semantic requirements, but they cannot independently establish that a layout looks right.
Layer 2: CSS and layout inspection
CSS determines how elements are presented. The browser resolves styles from stylesheets, inherited properties, the cascade, and other layout rules.
Using browser developer tools or automation code, you can inspect properties such as:
font-sizemarginpaddingdisplayalign-itemsjustify-contentgapwidthandheightcolorandline-height
Two browser APIs are particularly useful:
getComputedStyle(element)returns the element’s resolved CSS properties.element.getBoundingClientRect()returns its rendered position and dimensions relative to the viewport.
See the MDN documentation for computed styles and getBoundingClientRect().
These APIs help turn vague observations into measurable evidence.
Instead of saying, “The button looks slightly off,” you can determine that its left edge is 12px farther right than the reference element’s left edge.
Layer 3: Visual inspection
Visual inspection evaluates the rendered interface as a whole.
It helps detect problems that isolated DOM and CSS assertions may miss, including:
- Awkward visual hierarchy.
- Unexpected text wrapping.
- Overlapping elements.
- Inconsistent spacing across a page.
- Poor balance between components.
- Layout changes that technically satisfy individual CSS assertions but still look wrong.
This layer can be manual, automated through visual regression, or a combination of both.
The important distinction is that DOM inspection explains structure, CSS inspection explains resolved styling and geometry, and visual inspection evaluates the resulting experience.
No single layer replaces the others.
A Real-World Example: The Button That Looks Wrong
Imagine a team updates the shared CSS for buttons across its application.
The functional tests still pass. Login works. Checkout works. Forms submit correctly.
But on the checkout page, the primary button now sits farther away from the payment summary.
A screenshot comparison identifies a difference, but the team still needs to investigate it.
Here is a practical workflow.
Step 1: Confirm the visual difference.
Compare the current page against the approved screenshot at the same viewport size. Check whether the change is reproducible.
Step 2: Inspect the DOM.
Identify the button, its parent container, and nearby elements. Confirm that the expected components are rendered.
Step 3: Measure the geometry.
Use getBoundingClientRect() to compare the button’s position and dimensions with the expected layout or neighboring elements.
Step 4: Inspect computed CSS.
Check the button’s margins and padding, then inspect the parent container’s gap, alignment, and layout properties.
Step 5: Find the source of the regression.
Trace the unexpected computed value back to the relevant stylesheet or design-system rule. The browser’s computed style tells you the resolved value, not necessarily which source rule should be changed.
Step 6: Add a regression check.
If the spacing is an explicit requirement, add a targeted assertion. Keep the screenshot comparison as a separate check for broader visual regressions.
The result is a more actionable bug report and a test that can catch the same problem in the future.
Automating DOM and CSS Checks with Playwright
You don’t need a new testing framework to start checking UI geometry. Playwright can inspect elements, evaluate computed styles, and capture screenshots within the same test.
Here’s a TypeScript example:
import { test, expect } from '@playwright/test';
test('primary button has expected layout', async ({ page }) => {
await page.setViewportSize({
width: 1440,
height: 900
});
await page.goto('https://example.com/checkout');
const button = page.getByRole('button', {
name: 'Place order'
});
await expect(button).toBeVisible();
const layout = await button.evaluate((element) => {
const rect = element.getBoundingClientRect();
const styles = window.getComputedStyle(element);
return {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
fontSize: styles.fontSize,
marginBottom: styles.marginBottom,
display: styles.display
};
});
expect(layout.width).toBeGreaterThan(0);
expect(layout.height).toBeGreaterThan(0);
expect(layout.fontSize).toBe('16px');
});
This example checks visibility, dimensions, and font size. The 16px expectation is illustrative; use the actual requirement from your design specification.
Notice what the test doesn’t do: it doesn’t blindly assert exact coordinates for every element. Those values can change legitimately when the viewport, content, or layout changes.
For elements that must align, compare their geometry directly:
const buttonBox = await button.boundingBox();
const summaryBox = await page
.getByTestId('payment-summary')
.boundingBox();
expect(buttonBox).not.toBeNull();
expect(summaryBox).not.toBeNull();
if (buttonBox && summaryBox) {
expect(
Math.abs(buttonBox.x - summaryBox.x)
).toBeLessThanOrEqual(2);
}
This checks that the button and payment summary start at approximately the same horizontal position, allowing a tolerance of 2 CSS pixels. Use that tolerance only if it matches the intended design requirement.
A warning worth keeping in mind: a technically valid assertion can still encode the wrong design assumption. Validate the expected relationship before adding it to the test suite.
How to Choose the Right UI Testing Technique
| Testing technique | Best for | Main limitation |
|---|---|---|
| Functional UI tests | User actions, navigation, form submission | Don’t prove visual correctness |
| Screenshot comparison | Broad visual regressions | Doesn’t directly explain the cause |
| DOM assertions | Structure, attributes, semantics, visibility | Don’t establish visual quality |
| CSS assertions | Specific styling requirements | Can become brittle if overused |
| Geometry checks | Position, dimensions, alignment | Need meaningful reference rules |
| Responsive testing | Layout behavior across viewports | Requires deliberate viewport and content coverage |
| Accessibility testing | Keyboard access, names, semantics, contrast and other requirements | Requires dedicated checks; screenshots alone are insufficient |
In practice, a balanced suite uses each technique where it provides the most value.
Where Tools Like Captain Spyglass Fit
When a UI issue comes down to a few pixels, manually comparing elements and measuring their spacing can slow down investigation.
Captain Spyglass — Alignment Inspector is relevant to this problem because it helps developers inspect element dimensions, spacing, and alignment while working in the browser, with Figma validation as part of the workflow.
That makes it a useful companion to automated tests: use automation to detect repeatable regressions, then use inspection tools to investigate the actual rendered layout.
The distinction matters. An inspection tool can help you understand a layout issue, but it doesn’t automatically replace a regression suite, accessibility testing, or a clearly defined design specification.
Common Mistakes to Avoid
Treating every pixel difference as a defect
A new icon, intentional spacing change, or updated font can produce screenshot differences without introducing a bug.
Review changes against the approved design rather than blindly updating the baseline.
Asserting every CSS property
Tests that check dozens of incidental CSS values can become expensive to maintain. Prefer assertions for properties that matter to the requirement, such as a required font size, spacing rule, or alignment relationship.
Ignoring parent containers
When a child element appears misplaced, the cause might be its parent. Inspect the full layout relationship before changing the child’s styles.
Testing only one viewport
A layout that works at 1440px may fail at 768px or 320px. Test the breakpoints and viewport sizes that matter to your users and product requirements.
Updating visual baselines without investigating
A passing test after a baseline update doesn’t prove that the UI is correct. Understand the difference first, then approve the new baseline if the change is intentional.
Best Practices for Reliable UI Validation
- Start with requirements. Define the expected spacing, typography, alignment, and responsive behavior for important components.
- Use semantic locators. Prefer role-based or label-based locators when they fit the interaction and accessibility contract.
- Measure relationships, not arbitrary coordinates. Checking that two elements align can be more resilient than requiring one element to always appear at a fixed screen coordinate.
- Keep screenshot environments consistent. Standardize browser versions, viewport sizes, fonts, and test data wherever possible.
- Test multiple viewport sizes. Include representative desktop, tablet, and mobile layouts.
- Separate detection from diagnosis. A visual test can report a difference; DOM and CSS inspection can help locate its cause.
- Control dynamic content. Stabilize animations, timestamps, network-dependent data, and other sources of unnecessary screenshot noise.
- Keep accessibility in scope. Check keyboard behavior, accessible names, focus states, and applicable contrast and reflow requirements.
- Make assertions purposeful. Automate explicit design rules instead of encoding every incidental implementation detail.
- Review failures before changing baselines. A visual change should be understood before it becomes the new expected result.
Frequently Asked Questions
Is screenshot testing enough for UI automation?
No. Screenshot testing is useful for detecting visual differences, but it doesn’t fully validate DOM semantics, interaction behavior, accessibility, or the cause of a layout problem. Combining visual comparisons with targeted DOM, CSS, and functional checks provides better coverage.
What is the difference between visual testing and visual regression testing?
Visual testing is the broader practice of evaluating an interface’s appearance. Visual regression testing specifically looks for unintended visual changes between a current rendering and an approved baseline.
How can I test CSS properties using Playwright?
Use locator.evaluate() with window.getComputedStyle() to inspect resolved CSS properties. You can also use locator.boundingBox() to retrieve element geometry. Assert only the properties and relationships that are part of the intended UI requirement.
How do I detect misaligned buttons automatically?
Measure the relevant elements with getBoundingClientRect() or Playwright’s boundingBox(), then compare their positions or edges against a defined alignment rule. Allow a tolerance where appropriate and verify the rule at relevant viewport sizes.
Can a UI test pass while the page looks wrong?
Yes. Functional tests may pass even when spacing, typography, or alignment is incorrect. Screenshot tests may also miss subtle differences depending on their thresholds, coverage, and capture conditions.
What should QA engineers test beyond screenshots?
They should consider DOM structure, accessible names, computed CSS, dimensions, alignment, responsive reflow, keyboard interactions, and relevant visual regressions. The exact checks depend on the product’s requirements.
Which tools help investigate UI alignment issues?
Browser developer tools, Playwright, and dedicated layout-inspection tools can help. Captain Spyglass is one option for examining dimensions, spacing, and alignment directly in the browser.
Final Thoughts
A screenshot can show that something changed. It rarely tells the whole story.
When a button is misaligned, a heading uses the wrong font size, or a responsive layout breaks, the useful question isn’t simply whether the screenshot matches. It’s whether the interface meets its intended design and behavior requirements.
The most effective approach combines functional tests, visual regression checks, DOM inspection, CSS analysis, and targeted geometry assertions.
Don’t stop at finding a visual difference. Find out what caused it, decide whether it violates the requirement, and make sure your tests can catch it again.
