UNPKG

healenium-js

Version:

Healenium-style self-healing decorator for Playwright in TypeScript

88 lines (62 loc) โ€ข 1.79 kB
# Healenium-JS ๐Ÿงช A self-healing decorator for Playwright UI tests โ€” inspired by Healenium. Automatically heals broken selectors using fuzzy matching and maintains fallback history. ## โœจ Features - โœ… 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 ## ๐Ÿ“ฆ Installation ```bash npm install healenium-js ``` ## ๐Ÿš€ Usage ### 1. Decorate Failing Selector Method ```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'); } } ``` ### 2. Run Your Playwright Test ```bash npx playwright test ``` ### 3. View Fallback Data - โœ… `fallback-selectors.json` โ€” latest healed selectors - ๐Ÿ“š `selector-history.json` โ€” all past fallback selectors ## ๐Ÿง  How It Works - 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 ## ๐Ÿงช Example Test ```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(); }); ``` ## ๐Ÿ“œ License MIT ยฉ [Your Name]