← All Tools Free Browser Sandbox · Pro ZIP + Offline CLI ($7.00) Open Live Tool
Buy on Polar ($7.00)

Playwright Flaky Selector Auditor & Auto-Heal CLI Kit

Offline zero-dependency Python CLI for JS/TS & Python Playwright flakiness audits, SARIF 2.1.0 CI gates, and two-stage DOM locator healing.

Playwright test suites rarely fail because the application is broken. Far more often, CI turns red because a CSS-in-JS hash changed from .css-1x2y3z to .css-9k4m1p, a new wrapper <div> broke div > button:nth-child(2), or a waitForTimeout(1500) race lost to a slower CI runner. AI-powered PR agents can fix these tests automatically, but many engineering teams cannot ship proprietary DOM snapshots and internal test suites to third-party LLM endpoints.

Why this problem wastes time

Three subtle gaps break naive grep-based Playwright linters in real repositories:

  1. Multiline chains and comment false positives. Real Playwright tests wrap across lines (await page\n .frameLocator('#pay')\n .locator('button.css-1x2y3z')\n .click()) and mention forbidden patterns inside comments. A line-by-line regex misses the multiline call while firing on comments, and blindly rewriting .locator(...) drops the frameLocator('#pay') receiver chain.
  2. The broken selector paradox. If a selector already failed in CI because a class hash was renamed, an exact querySelector lookup against the captured DOM returns zero elements and suggests nothing. You need a two-stage resolver: exact CSS matching for upgrading live brittle selectors, plus fuzzy token healing against interactive ARIA elements when a selector returns zero matches.
  3. Ambiguous replacements. Suggesting getByRole('button', { name: 'Save' }) when a page contains two Save buttons causes Playwright strict-mode failures on the very next run unless you check DOM uniqueness first.

Step-by-step workflow

A deterministic offline healing pipeline works in three stages:

  1. Scan tests with a comment-safe, balanced-parenthesis parser so multiline locators, template strings, and receiver chains stay intact across both JS/TS (*.spec.ts) and Playwright Python (*_test.py).
  2. Capture a DOM snapshot on failure via Playwright's afterEach hook (page.content()), keeping all inspection local.
  3. Resolve replacements using WAI-ARIA accessible-name priority (aria-label -> aria-labelledby -> <label for> -> ancestor <label> -> element text) and verify matches_in_dom === 1.

Here is a self-contained Python 3 snippet using the standard library that masks JS/TS comments while preserving line offsets and extracts multiline .locator(...) spans:

import re


def mask_js_comments(source: str) -> str:
    chars = list(source)
    n, i = len(source), 0
    while i < n:
        ch = source[i]
        if ch in ('"', "'", "`"):
            q = ch
            i += 1
            while i < n:
                if source[i] == "\\":
                    i += 2
                    continue
                if source[i] == q:
                    i += 1
                    break
                i += 1
            continue
        if source[i : i + 2] == "//":
            while i < n and source[i] != "\n":
                chars[i] = " "
                i += 1
            continue
        if source[i : i + 2] == "/*":
            chars[i : i + 2] = [" ", " "]
            i += 2
            while i < n and source[i : i + 2] != "*/":
                if chars[i] != "\n":
                    chars[i] = " "
                i += 1
            if i + 1 < n:
                chars[i : i + 2] = [" ", " "]
                i += 2
            continue
        i += 1
    return "".join(chars)

Common pitfalls & edge cases

Automating it in seconds

Use the Free Browser Sandbox on the tool page to paste a single Playwright TypeScript snippet alongside an HTML DOM snapshot, flag PW001–PW007 flakiness issues, verify DOM uniqueness (matches_in_dom), and preview unified patch diffs or export Markdown/JSON reports.

When you want repository-wide automation, the Pro Offline Bundle delivers pw_audit.py (recursive JS/TS + Playwright Python scanning, SARIF 2.1.0 output, and safe --apply patching with .bak backups), trace_diff.py (two-stage exact + fuzzy DOM resolver), capture_dom_on_fail.ts, and a ready-to-drop .github/workflows/playwright-audit.yml CI workflow—all offline with zero external dependencies.

Open Interactive Tool / Demo
Playwright Flaky Selector Auditor & Auto-Heal CLI Kit
Full Bundle / Pro ($7.00) — Offline CLI, source & assets (.zip) · Instant checkout via Polar
Buy on Polar