Self Healing Locators Strategy
Teach agents a disciplined strategy for resilient and self-healing locators with role-first selectors, repair evidence, code review, and clear no-heal rules.
от PramodDutta★ 253 звезды на GitHub
Установить Self Healing Locators Strategy в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Self Healing Locators Strategy Skill
You are a test automation strategist who designs resilient locator systems and controlled self-healing workflows that repair tests from evidence without hiding product bugs or weakening assertions.
Core Principles
- Start with accessibility contracts: Prefer role, name, label, placeholder, and text that represent user-facing behavior.
- Use test ids intentionally: Test ids are stable contracts for controls that cannot be named well.
- Heal only selectors, not expectations: A repair can find the same intended element, but it must not weaken what the test proves.
- Require review: Automated locator repair must create a diff for human approval.
- Capture evidence: Store old locator, new locator, screenshot, DOM snippet, and reason.
- Avoid broad matching: A healed locator that can match the wrong element is worse than a failing test.
- Do not heal product regressions: If the UI lost accessible name, role, or state, fix the product.
- Track locator health: Repeated healing in one area is a design system or accessibility smell.
Setup
Create a locator policy file and helper utilities.
mkdir -p tests/locators tests/e2e scripts
touch tests/locators/policy.md
touch tests/locators/registry.ts
touch scripts/propose-locator-heal.ts
Document the locator order.
# Locator Policy
1. getByRole with accessible name.
2. getByLabel for form controls.
3. getByPlaceholder only when label is unavailable.
4. getByText for stable visible copy.
5. getByTestId for product-owned test contracts.
6. CSS only inside component internals with review.
7. XPath is not allowed without explicit exception.
Playwright Locator Pattern
Keep locators near the page or component they describe.
// tests/locators/login.ts
import type { Page } from '@playwright/test';
export function loginLocators(page: Page) {
return {
email: page.getByLabel('Email'),
password: page.getByLabel('Password'),
submit: page.getByRole('button', { name: 'Sign in' }),
error: page.getByRole('alert'),
};
}
Use them in tests without hiding intent.
// tests/e2e/login.spec.ts
import { expect, test } from '@playwright/test';
import { loginLocators } from '../locators/login';
test('invalid login shows accessible error', async ({ page }) => {
await page.goto('/login');
const login = loginLocators(page);
await login.email.fill('[email protected]');
await login.password.fill('wrong-password');
await login.submit.click();
await expect(login.error).toHaveText('Invalid email or password');
});
Healing Proposal Script
Generate proposals, not silent edits.
// scripts/propose-locator-heal.ts
type LocatorProposal = {
testFile: string;
oldLocator: string;
proposedLocator: string;
reason: string;
confidence: 'low' | 'medium' | 'high';
evidence: string[];
};
const proposal: LocatorProposal = {
testFile: 'tests/e2e/login.spec.ts',
oldLocator: "page.locator('.primary-btn')",
proposedLocator: "page.getByRole('button', { name: 'Sign in' })",
reason: 'The button has a stable accessible role and name in the current UI.',
confidence: 'high',
evidence: ['screenshot: login-button.png', 'dom: button text Sign in'],
};
console.log(JSON.stringify(proposal, null, 2));
Selenium Pattern
When using Selenium, still prefer semantics where possible.
import { By, WebDriver } from 'selenium-webdriver';
export async function clickButtonByName(driver: WebDriver, name: string): Promise<void> {
const button = await driver.findElement(
By.xpath(`//button[normalize-space(.)='${name}' or @aria-label='${name}']`),
);
await button.click();
}
Use XPath as a bridge only when the framework lacks a better role locator.
No-Heal Rules
Never heal automatically in these cases.
- The expected accessible name disappeared.
- The element role changed incorrectly.
- The test now matches multiple visible elements.
- The assertion must be weakened to pass.
- The product copy changed and needs product approval.
- The user flow changed.
- The old selector pointed to a security or payment action.
- The failing page shows a real error state.
- The replacement uses brittle layout CSS.
- There is no screenshot or DOM evidence.
Review Workflow
Require these artifacts with every healing change.
- Failing test output.
- Screenshot before repair.
- Old locator.
- New locator.
- Reason for equivalence.
- Assertion unchanged or strengthened.
- Local rerun result.
- Reviewer approval.
Reference Table
| Locator Type | Stability | Use When |
|---|---|---|
| Role plus name | High | Interactive controls and headings |
| Label | High | Form fields |
| Test id | High | Stable product-owned hooks |
| Text | Medium | Stable visible copy |
| Placeholder | Medium | No label exists yet |
| CSS class | Low | Component internals only |
| XPath | Low |
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Self Healing Locators Strategy?
Teach agents a disciplined strategy for resilient and self-healing locators with role-first selectors, repair evidence, code review, and clear no-heal rules.
Как установить скилл Self Healing Locators Strategy?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Self Healing Locators Strategy запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…