AwarseLabs

Fixing Flaky Selectors in Playwright: Ephemeral Auto-Healing

Selector drift is the primary driver of pipeline flakiness in web test suites. When frontend teams refactor CSS classes or update container wrappers, rigid locators fail.

Why Strict Locators Rot

Playwright’s default strict mode prevents ambiguities by throwing errors when locators resolve to zero or multiple elements. In continuous deployment pipelines, minor UI adjustments trigger false alarms:

  1. Dynamic CSS Modules: Generated hash suffixes change across branch builds.
  2. Component Swaps: A <button> changes to an interactive wrapper or nested SVG.
  3. Accessibility Shift: aria-label or role attributes shift during localization updates.

The Ephemeral FastMCP Approach

Instead of streaming DOM snapshots to third-party cloud testing providers, healwright catches selector lookup errors locally and invokes an ephemeral FastMCP server to re-anchor the target element:

pip install healwright
from healwright import HealwrightHook

# Register the local healer hook
hook = HealwrightHook(cache_path=".healwright_cache.json")