Self-Healing Utility for Playwright test execution.
Features
- Multi-strategy element finding with retry logic
- Healing history: records which strategy index succeeded per element so future runs try the winning strategy first (adaptive self-healing)
- Comprehensive ARIA role coverage in assertion transforms
- Code transform engine that rewrites raw Playwright calls into self-healing helpers
Exports
recordHealing— Record a successful healing result.recordHealingFailure— Record a failed healing attempt.getHealingHint— Get the previously-successful strategy index.getHealingHistoryForTest— Serialise healing history for runtime injection.getSelfHealingHelperCode— Generate the runtime helper code string.applyHealingTransforms— Rewrite Playwright code to use self-healing helpers.CORE_RULES— Native Playwright rules for local models (~200 tokens).SELF_HEALING_PROMPT_RULES— Full self-healing helper rules for cloud models.getPromptRules— Tier-aware getter: returns CORE_RULES or full rules.
- Source:
Methods
(static) applyHealingTransforms(code) → {string}
Rewrite raw Playwright code to use self-healing helpers (safeClick, safeFill, safeExpect).
Only transforms human-readable text selectors — CSS/XPath selectors are left untouched.
Parameters:
| Name | Type | Description |
|---|---|---|
code |
string | Raw Playwright test code. |
- Source:
Returns:
Transformed code with self-healing helper calls.
- Type
- string
(static) getHealingHint(testId, action, label) → {number}
Get the previously-successful strategy index for an action+label, or -1.
Parameters:
| Name | Type | Description |
|---|---|---|
testId |
string | Test ID. |
action |
string | Action type. |
label |
string | Element label/text. |
- Source:
Returns:
Strategy index (0-based), or -1 if no history.
- Type
- number
(static) getHealingHistoryForTest(testId) → {Object.<string, number>}
Serialise healing history for a test so it can be injected into runtime code.
Parameters:
| Name | Type | Description |
|---|---|---|
testId |
string | Test ID. |
- Source:
Returns:
Map of "action::label" → winning strategy index.
- Type
- Object.<string, number>
(static) getPromptRules(tier) → {string}
Return the appropriate prompt rules for the given tier.
"cloud"— full exhaustive rules (SELF_HEALING_PROMPT_RULES)"local"— compact core rules only (CORE_RULES)
Parameters:
| Name | Type | Description |
|---|---|---|
tier |
"cloud" | "local" | The prompt tier. |
- Source:
Returns:
Prompt rules string.
- Type
- string
(static) getSelfHealingHelperCode(healingHintsopt) → {string}
Generate the self-healing runtime helper code as a string for injection
into Playwright test execution context. Includes findElement, safeClick,
safeFill, safeExpect, and retry logic.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
healingHints |
Object.<string, number> |
<optional> |
Map of |
- Source:
Returns:
JavaScript code string to be prepended to test execution.
- Type
- string
(static) recordHealing(testId, action, label, strategyIndex)
Record a successful healing result.
Parameters:
| Name | Type | Description |
|---|---|---|
testId |
string | Test ID (e.g. |
action |
string | Action type ( |
label |
string | Element label/text used in the action. |
strategyIndex |
number | Index of the winning strategy in the waterfall. |
- Source:
(static) recordHealingFailure(testId, action, label)
Record a failed healing attempt (all strategies exhausted).
Parameters:
| Name | Type | Description |
|---|---|---|
testId |
string | Test ID. |
action |
string | Action type. |
label |
string | Element label/text. |
- Source: