Skip to content

Repository files navigation

self-healing-automation

A C#/.NET 8 + Playwright + Reqnroll (BDD/Gherkin) test framework where a broken locator gets healed by Claude at test-run time — and a second layer that heals whole CI build failures.

How it works

A Playwright test resolves a selector. If it doesn't resolve to a visible element, SelfHealingExtensions.HealAndRetryAsync asks Claude (Framework/ClaudeLocatorHealer.cs, raw HTTP to the Anthropic Messages API, no SDK) to suggest a replacement based on the page's current DOM and the locator's stated intent — up to 3 attempts. Every attempt is logged (Framework/HealingLog.cs) to artifacts/healing/.

  • On success: the test passes, and a -HEALED.md artifact tells a human to apply the fix permanently in the Page Object. Claude doesn't rewrite source files mid-run.
  • After 3 failed attempts: throws SelfHealingExhaustedException ("Claude couldn't do it, check manually") and writes a -FAILED.md artifact with the full attempt log.

Without ANTHROPIC_API_KEY set, the healer runs in a deterministic "no-heal mode" — free, no network call, tests still pass/fail predictably.

Two layers of healing

  1. Runtime locator healing (above) — inside a single test, scoped, fast, never touches source files.
  2. CI build healing (.github/workflows/ci-self-heal.yml) — when the whole build fails on main for any reason (not just a healable locator), a second workflow triggers on that failure, checks out the failing commit, and runs Claude Code headless to diagnose the failure, fix it, verify with dotnet test, and open a PR. It never pushes to main directly — a human still reviews and merges, same principle as layer 1, one level up the pipeline.

Run it locally

dotnet build
pwsh bin/Debug/net8.0/playwright.ps1 install --with-deps chromium   # first run only
dotnet test --filter "TestCategory!=manual"

The @manual-tagged scenario in Features/SelfHealing.feature demonstrates the exhausted-after-3 "check manually" path on purpose and is excluded from CI — run it explicitly if you want to see it:

dotnet test --filter "TestCategory=manual"

CI

.github/workflows/self-healing.yml runs the suite on every push/PR to main, with a real ANTHROPIC_API_KEY secret so the live-healing scenario genuinely exercises the Claude call. Screenshots and healing-log artifacts are uploaded regardless of outcome.

Author

Devbrat Verma — Senior SDET, 10+ years in test automation.

About

Self-healing Playwright/Reqnroll test framework with AI-driven locator and CI healing

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages