Self-Healing Tests: Auto-Fixing Broken Tests with AI

Self-Healing Tests: Auto-Fixing Broken Tests with AI Your team spends 20–40% of its time maintaining the test suite — not writing new tests, but fixing broken ones. The culprits: UI changes (locator no longer finds the element), API changes (response structure altered), or business logic changes

AI Development Areas

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1284
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1240
  • image_logo-advance_0.webp
    B2B Advance company logo design
    696
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_logo-aider_0.webp
    AIDER company logo development
    918
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1032

Self-Healing Tests: Auto-Fixing Broken Tests with AI

Your team spends 20–40% of its time maintaining the test suite — not writing new tests, but fixing broken ones. The culprits: UI changes (locator no longer finds the element), API changes (response structure altered), or business logic changes (outdated assertion). Self-Healing Tests is an ML layer that detects the cause of failure and automatically applies a fix without human intervention. It’s a practical application of AI for testing and ML for QA. Budget savings on test maintenance can reach 50%, and flaky tests drop by up to 70%. Contact us to get a project estimate.

Compare: manually fixing one flaky test takes an average of 2–4 hours. Self-Healing reduces that to 5 minutes for reviewing the proposed fix — a 24–48x speedup.

How Self-Healing Tests Works

The system operates in two modes: proactive — preemptively updating locators when new frontend is deployed, and reactive — fixing after a CI/CD failure.

Core system consists of three modules:

  • Failure Classifier — an NLP model (fine-tuned DistilBERT) that classifies failure type from stack trace: ElementNotFound, AssertionError, TimeoutError, NetworkError.
  • Selector Healer — for ElementNotFound, finds an alternative locator via DOM analysis; trained on pairs (old locator → new locator) from commit history.
  • Assertion Fixer — for AssertionError, compares actual and expected values, identifies the change pattern (numeric drift, string format change, JSON structural change) and suggests an updated assertion.
class SelfHealingRunner: def __init__(self, model_path: str): self.classifier = FailureClassifier.load(model_path) self.healer = SelectorHealer() self.assertion_fixer = AssertionFixer() def run_with_healing(self, test_fn, max_retries: int = 2): for attempt in range(max_retries + 1): try: return test_fn() except Exception as e: if attempt == max_retries: raise failure_type = self.classifier.predict(str(e)) if failure_type == "ElementNotFound": self.healer.apply_fix(e) elif failure_type == "AssertionError": self.assertion_fixer.suggest(e) 

What Selector Healing Delivers

For Selenium or Playwright tests, the main source of flakiness is fragile CSS selectors like #app > div:nth-child(3) > button. After a layout change, such a locator fails.

Recovery algorithm:

  1. Parse the current DOM at the moment of failure.
  2. Extract features of the lost element from the test source: tag type, text content, aria-label, sibling elements.
  3. Build an element embedding (features → vector via trained encoder).
  4. Find the nearest element in the current DOM by cosine similarity.
  5. Generate a new locator: prefer data-testid, then aria-label, then XPath with text().

Recovery accuracy on a test dataset (5000 pairs): 87% correct fixes. Self-Healing speeds up locator repair by 24–48x compared to manual search. We guarantee that after a two-week report-only mode, the system is ready for auto-fixes.

Example of Selector Healer in actionThe old locator was `#menu > div:nth-child(3) > button`. After a menu redesign, the button moved. The system found the element by aria-label "Add to cart" and generated `button[aria-label="Add to cart"]`. The test passed.

How We Integrate into CI/CD

# .github/workflows/tests.yml - name: Run tests with self-healing run: | pytest tests/ --self-healing-mode=auto \ --healing-model=./models/healing_v2.pkl \ --max-healing-retries=2 \ --healing-report=artifacts/healing_report.json 

After each healing event, the system creates a Pull Request with the suggested fix — the engineer only does code review instead of debugging from scratch. On our projects with 500+ e2e tests, auto-healing closes 60–70% of failures without QA involvement, saving over 100 person-hours per month. For Playwright, self-healing is fully implemented; for Selenium, auto-repair works through the Selector Healer. Our experience across 10+ projects confirms consistent results.

Supported Frameworks and Technologies

Framework Test Type Support Status
Playwright E2E, component Full
Selenium WebDriver E2E Full
Cypress E2E Partial (via proxy)
pytest API, unit Assertion Fixing only
JUnit/TestNG Unit, integration Assertion Fixing only

Implementation Stages

  1. Audit test base: analyze failure frequency by type, identify most flaky tests.
  2. Collect dataset from CI history — pairs (failed test, fix commit).
  3. Train Failure Classifier and Selector Healer on your project.
  4. Integrate into CI/CD pipeline with report-only mode for the first 2 weeks.
  5. Switch to auto-fix mode with confidence threshold > 0.85.
Test Base Size Implementation Time
Up to 200 tests 2–3 weeks
200–1000 tests 3–5 weeks
Over 1000 tests 5–8 weeks

What’s Included

  • Full audit of test infrastructure and failure history.
  • Training custom models on your project data.
  • CI/CD integration (GitHub Actions, GitLab CI, Jenkins).
  • Setup and operation documentation.
  • Team training (2-hour webinar).
  • 3 months of post-implementation support.

After implementation, failed tests drop by 70% — confirmed by our clients’ experience. Self-Healing automates regression testing and reduces flaky tests.

When to Order Implementation

If your team spends more than 20% of its time on test maintenance and flaky tests increase every sprint — contact us. We’ll assess your project in 1–2 days and propose a solution. Order implementation and get a free consultation on your test base.