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.
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.mdartifact 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.mdartifact 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.
- Runtime locator healing (above) — inside a single test, scoped, fast, never touches source files.
- CI build healing (
.github/workflows/ci-self-heal.yml) — when the whole build fails onmainfor 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 withdotnet test, and open a PR. It never pushes tomaindirectly — a human still reviews and merges, same principle as layer 1, one level up the pipeline.
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".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.
Devbrat Verma — Senior SDET, 10+ years in test automation.