healenium-js
Version:
Healenium-style self-healing decorator for Playwright in TypeScript
88 lines (62 loc) โข 1.79 kB
Markdown
A self-healing decorator for Playwright UI tests โ inspired by Healenium. Automatically heals broken selectors using fuzzy matching and maintains fallback history.
- โ
Self-heals selectors using fuzzy text-matching
- ๐ Tracks fallback usage and selector history
- ๐งฉ Decorator-based usage via `@Healenium`
- ๐ Automatically updates fallback selectors
- ๐งฐ Written in TypeScript, ready for npm publishing
```bash
npm install healenium-js
```
```ts
import { Healenium } from 'healenium-js';
class MyTests {
page: Page;
constructor(page: Page) {
this.page = page;
}
@Healenium('#non-existent-button')
async clickMissingButton() {
await this.page.click('#non-existent-button');
}
}
```
```bash
npx playwright test
```
- โ
`fallback-selectors.json` โ latest healed selectors
- ๐ `selector-history.json` โ all past fallback selectors
- When a selector fails, the plugin:
1. Extracts its text
2. Uses Levenshtein distance to find a similar element
3. Generates a new selector and stores it
4. Re-runs the test using the new selector
```ts
import { test as base } from '@playwright/test';
import { Healenium } from 'healenium-js';
class Demo {
page: Page;
constructor(page: Page) {
this.page = page;
}
@Healenium('#broken-selector')
async triggerHealer() {
await this.page.click('#broken-selector');
}
}
base('Healenium demo', async ({ page }) => {
const t = new Demo(page);
await page.goto('https://example.com');
await t.triggerHealer();
});
```
MIT ยฉ [Your Name]