Skip to Content
SDODS
Guides

Self-healing locators

How SDODS recovers from a broken locator, scores alternatives, records every heal and proposes fixes.

What you'll learn

When healing kicks in, how candidates are built from the context you declare, how they are scored, what is recorded, and how repeated heals turn into page-object patches.

Declare context

readonly submit = this.heal.locator(this.page.locator('#login-button'), {
  role: 'button', name: 'Login', testId: 'login-button', description: 'login button',
});

Resolution

Worst case adds about 4.5 seconds, not the 30-plus seconds of naive fallback chains. Negative assertions are never healed.

sdods.project.yaml
heal:
  enabled: true
  primaryTimeoutMs: 3000
  probeTimeoutMs: 1500
  minScore: 0.6
  actions: [click, fill, select, assert, hover, check]

What is recorded

Every heal is attached to the scenario (sdods/heal/<step>/<n>), appended to heal.jsonl in the run directory, annotated on the test, and logged with the suggested rewrite. With a database, heals feed heal_events and locator_stats.

bun run sdods heal report --last
bun run sdods heal report -p demo-shop --write-history

Healing in CI

Healing must never silently hide a regression. On your machine a heal is a convenience: the locator drifted, the step carried on, and the warning tells you to update the page object. In CI the same heal means the application changed under the suite, and a green check that hides that is worse than a red one. So when CI is set (or ci: true in the env yaml), heal.ciMode decides:

heal.ciModeIn CI
warn (default)heals and carries on, then lists every heal: a ::warning annotation per locator on GitHub Actions, a table in the job summary, and a warning line on any other CI
failfails the step with HEAL_BLOCKED_IN_CI, naming the locator that would have healed it, and records the event
offno healing: the primary locator works or the step fails with Playwright's own error
heal:
  ciMode: fail # release gates: a drifted locator blocks the release

warn is the default because a team adopting SDODS should not have its pipeline turn red the day it enables healing; the annotation still puts every heal in front of the person reading the run. Use fail for release gates. Outside CI ciMode has no effect.

Screenshot fallback

Off by default. With heal.vision: true and TYPESAFE_API_KEY set, a heal the DOM cannot decide gets one more try: nothing scored at least minScore, or the best candidate still matches several elements (two "Submit" buttons). SDODS takes a viewport screenshot, scales it to at most 1568 px a side, and asks TypeSafe two questions in one request: where the described element is (a Box) and whether it is on screen at all (a Noul). It then acts on the candidate element whose rect overlaps the box most.

heal:
  vision: true
  • The heal is recorded like any other, with strategyUsed: "vision-box", the .nth(i) selector it picked and a vision block (presence, box, overlap). ciMode applies: warn lists it, fail blocks it.
  • That .nth(i) selector picks the element by its position, so it breaks when the order changes. The heal log, sdods heal, insights and the CI summary mark it as positional: give the element a test id or an exact name and put that in the page object instead.
  • The element rects are measured right after the screenshot. If the chosen element has moved by the time TypeSafe answers, the heal does not act on it.
  • A presence under 0.6 fails the step with HEAL_FAILED, even when the DOM had an ambiguous guess.
  • A box that overlaps no candidate, or several about equally, decides nothing: the heal falls back to what the DOM found.
  • A failed TypeSafe call is logged and recorded as vision.error; it is never read as "not there".
  • Without a key the fallback is skipped and healing works exactly as before. The screenshot leaves the machine for TypeSafe, so leave the flag off for pages that show data you cannot send.

Confirming a heal by a weak clue

A unique DOM match is not always the right element. When the page object's element is gone, another control with the same role and name, or the same text, is still a unique match: the order form's "Submit" button disappears with an empty cart, and the newsletter's "Submit" scores 1.0 by role and name. So with heal.vision: true and a key set, a heal won by one of these strategies is checked on the screenshot before SDODS acts on it:

Winning strategyConfirmed?Why
role (role and name), text-exact, text-partialyesunrelated controls share a role and name or a word like "Submit"
testid, labelnothey name the element itself
placeholdernoit only matches form fields and ranks above text in the locator strategy; an empty field with the same hint is rare enough not to pay a call for
title, alt, cssnoan attribute or selector the author wrote for that element
role-filternothe page object's own locator, narrowed to a role

The rule follows the strategy that won the heal, not the clues in the context: a context with a role, a name and a test id that still matches is healed by role (it scores 1.0, the test id 0.95), so it is confirmed.

  • The check is the request the fallback sends (a presence Noul and a Box about the described element), after the healed element is scrolled into view, as the action would scroll it.
  • A presence under 0.6, or a box that does not overlap the healed element (IoU under 0.2), refuses that match, and the page is scrolled back to where it was. SDODS then tries the next unique candidate: a strong one (a test id or a label that still matches) is used as is, and a weak one is checked too, at most two checks per heal. A match on an element already refused is skipped. When no candidate is left, the step fails with HEAL_FAILED and nothing is clicked or filled. The event records vision.confirm: "refused".
  • A failed TypeSafe call keeps the DOM heal as it would be without the flag, recorded as vision.confirm: "unconfirmed" with the error. A failure is never read as "not there".
  • An off-screen or zero-size weak match is never refused: the screenshot cannot show it, so there is no call, and the heal stays unconfirmed. The same goes for an element that moves more than 2 px while TypeSafe answers (the fallback's rule): the answer no longer describes it, so the DOM heal stands, unconfirmed.
  • Under ciMode: fail the heal is blocked anyway, so there is no check and no screenshot leaves the machine: the step fails with HEAL_BLOCKED_IN_CI as before.
  • A confirmed heal is recorded with vision.confirm: "confirmed" and the overlap.
  • Cost: one TypeSafe call, and one screenshot sent, per heal won by a weak clue, every time it happens (two when the first match is refused and the next candidate is weak too). Heals by a test id or a label cost nothing. The answer is not cached: whether the element is the right one depends on the page's state at that moment (a full cart or an empty one), which is exactly what a cached answer would miss. A heal that repeats is a page object to fix; until then each occurrence is checked.

From heal to fix

After three identical successful heals of the same locator, insights produce a page-object patch proposal, deterministically when the page object uses heal.locator, otherwise through the healer agent. Review and accept it like any other proposal.

Next steps

Using an AI coding agent? Install SDODS:

Install the SDODS plugin in Claude Code: skills, subagents, commands and the MCP server.

  1. /plugin marketplace add https://sdods.com/skills.git
  2. /plugin install sdods@sdods
Learn more about using SDODS with AI tools

On this page