Back to blog
Self-Healing

Self-Healing Tests: Never Fix a Broken Selector Again

Piotr Gebski5 min read

You've been there: a designer tweaks a button's class name, and suddenly 15 tests fail. The app works perfectly — the tests are just broken. This is selector drift, and it's the silent killer of test suites.

The Selector Drift Problem

Every E2E test relies on selectors to find elements on the page. When those selectors change — even slightly — tests break. Common causes:

  • **CSS class renames** during refactoring
  • **Component library updates** that change internal DOM structure
  • **Responsive design changes** that reorganize elements
  • **Dynamic IDs** generated by frameworks like React or Vue
  • The result? Teams spend hours every sprint fixing tests that aren't actually testing anything new. They're just chasing selector changes.

    How Self-Healing Works

    Self-healing tests detect when a selector breaks and automatically find the correct replacement. Here's the process:

  • **Detect the failure** — When a test run fails because an element can't be found, the system captures the error context including the broken selector and the current page DOM.
  • **Analyze the DOM** — The AI crawls the current page structure to understand what changed.
  • **Find the match** — Using the test's intent (what it was trying to click, fill, or assert), the AI identifies the correct element in the new DOM.
  • **Update the selector** — The broken selector is replaced with a new, stable one — preferring data-testid attributes, ARIA roles, and text content.
  • **Create a new version** — The healed test is saved as a new version, preserving the history so you can review and roll back if needed.
  • Before and After

    Before (broken test):

    // This selector breaks when the button class changes

    await page.click('.btn-primary.submit-form');

    After (healed test):

    // Self-healing picks a more resilient selector

    await page.getByRole('button', { name: 'Submit' });

    The healed version uses Playwright's recommended locator strategy — role-based selectors that are resistant to CSS changes.

    Why Version History Matters

    Every heal creates a new version of the test. This gives you:

  • Full audit trailsee exactly what changed and when
  • Rollback capabilityrevert to any previous version
  • Confidencereview AI changes before deploying to CI
  • Reducing Maintenance by 70%

    Teams using self-healing report dramatic drops in test maintenance time. Instead of manually hunting for broken selectors, the AI does it automatically. Your test suite stays green without constant human intervention.

    Setting It Up in Testoro

    In Testoro, self-healing is built in. When a test run fails, you'll see a "Heal" button on the test detail page. One click triggers the AI to analyze the failure and generate a fixed version. For Pro plan users, healing happens automatically — no manual intervention needed.

    Stop fighting selector drift. Let your tests heal themselves.