Synthesizing Automated Test Suites: How SnapTest Generates Playwright Specs from DOM Snapshots
How our in-house test generator parses live DOM trees, generates resilient accessible role selectors, and outputs ready-to-run Playwright tests without fragile XPath locators.
Akusara Studio Labs
Frontend & Tooling

How our in-house test generator parses live DOM trees, generates resilient accessible role selectors, and outputs ready-to-run Playwright tests without fragile XPath locators.
The Problem with Fragile Locators
When software teams write browser test suites, test longevity is usually ruined by brittle selectors. A developer changes a CSS utility class or refactors a parent container, and dozens of end-to-end tests fail across the pipeline—even though the user-facing functionality works fine.
When we built SnapTest, our objective was to automate test generation without generating throwaway test code.
DOM Tree Pruning and Accessible Selector Heuristics
SnapTest takes a live DOM snapshot or product user flow and generates Playwright specifications. Rather than recording raw mouse coordinates or recording volatile classes, the synthesis engine follows a strict hierarchy of locators:
- Explicit ARIA Roles and Accessible Names:
Prefer page.getByRole('button', { name: 'Submit Order' }) over nested class queries.
- User-Facing Labels and Placeholders:
Prefer page.getByLabel('Work Email') or page.getByPlaceholder('Enter team name').
- Explicit Test IDs as Fallback:
Only fall back to page.getByTestId('checkout-summary') when visual text is intentionally dynamic.
// Generated Playwright test spec produced by SnapTest
import { test, expect } from '@playwright/test';
test('completes organization workspace onboarding', async ({ page }) => {
await page.goto('/onboarding');
// Accessible role locator ensures resilient element targeting
await page.getByRole('textbox', { name: 'Workspace Name' }).fill('Acme Engineering');
await page.getByRole('combobox', { name: 'Team Size' }).selectOption('10-50');
await page.getByRole('button', { name: 'Create Workspace' }).click();
// Web-first auto-retrying assertion
await expect(page.getByRole('heading', { name: 'Welcome to Acme Engineering' })).toBeVisible();
await expect(page).toHaveURL(/\/dashboard/);
});Synthesis vs Recording
Standard record-and-replay tools produce procedural clicks without assertions. SnapTest synthesizes preconditions, actionable steps, and verifiable postconditions:
- It observes network mutation responses (e.g.
POST /api/v1/workspaces) and inserts assertions checking that successful server responses trigger the corresponding UI transitions. - It automatically creates negative edge-case test paths, such as attempting form submission with invalid email inputs or empty required fields.
The Engineering Outcome
By generating tests that target semantic structure rather than volatile layout attributes, QA and engineering teams reduce test suite maintenance by more than 60%.
Published by Akusara Studio Labs
Frontend & Tooling
Akusara Digital is an engineering and product studio building mission-critical software, custom SaaS platforms, and developer tooling.
Read Next from Akusara
All Articles
Eliminating 'Cannot Reproduce': Why Visual & Network Diagnostics Matter in Bug Reports
The engineering story behind Bugsnap. How capturing DOM mutations, network payloads, and console logs at the point of failure cuts triage time by 70%.
Eliminating Flaky Tests in CI: Deterministic Wait Patterns and DOM State Guards
Why waitForTimeout is an anti-pattern. How web-first assertions, auto-waiting locators, and isolated test workers cut CI false negatives to zero.
