{"id":51043665,"url":"https://github.com/axeforging/playwright-smart-locators","last_synced_at":"2026-06-22T12:02:07.379Z","repository":{"id":342136955,"uuid":"1168827360","full_name":"AxeForging/playwright-smart-locators","owner":"AxeForging","description":"AI-powered self-healing smart web locators for Playwright tests.","archived":false,"fork":false,"pushed_at":"2026-03-04T22:16:11.000Z","size":47,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-06T00:13:26.394Z","etag":null,"topics":["ai-testing","auto-healing","dom","e2e-testing","flaky-tests","local","ollama","playwright","playwright-plugin","qa-automation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AxeForging.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-27T21:01:52.000Z","updated_at":"2026-06-04T04:55:14.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/AxeForging/playwright-smart-locators","commit_stats":null,"previous_names":["axeforging/playwright-smart-locators"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AxeForging/playwright-smart-locators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxeForging%2Fplaywright-smart-locators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxeForging%2Fplaywright-smart-locators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxeForging%2Fplaywright-smart-locators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxeForging%2Fplaywright-smart-locators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AxeForging","download_url":"https://codeload.github.com/AxeForging/playwright-smart-locators/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxeForging%2Fplaywright-smart-locators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34647750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-testing","auto-healing","dom","e2e-testing","flaky-tests","local","ollama","playwright","playwright-plugin","qa-automation"],"created_at":"2026-06-22T12:02:05.425Z","updated_at":"2026-06-22T12:02:07.371Z","avatar_url":"https://github.com/AxeForging.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# playwright-smart-locators\n\n[![NPM Version](https://img.shields.io/npm/v/@axeforging/playwright-smart-locators.svg?style=flat-square)](https://www.npmjs.com/package/@axeforging/playwright-smart-locators)\n[![NPM Weekly Downloads](https://img.shields.io/npm/dw/@axeforging/playwright-smart-locators.svg?style=flat-square)](https://www.npmjs.com/package/@axeforging/playwright-smart-locators)\n[![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/@axeforging/playwright-smart-locators.svg?style=flat-square)](https://www.npmjs.com/package/@axeforging/playwright-smart-locators)\n\n**AI-powered developer tool for diagnosing and fixing broken Playwright locators during local development.**\n\n`playwright-smart-locators` helps developers quickly diagnose and fix broken CSS selectors in End-to-End (E2E) test scripts during local development. When a locator fails, it intercepts Playwright's `TimeoutError`, evaluates the broken selector against live and cached DOMs, and uses an AI LLM to suggest a corrected locator. It then generates a `-healed.ts` suggestion file for you to review and adopt into your codebase.\n\nWe extensively tested with local 7B models (e.g., **Qwen 2.5 Coder 7B** via Ollama and Open WebUI) to provide robust healing suggestions without significant API costs.\n\n---\n\n## 🔒 Data Privacy \u0026 Enterprise Security\n\nFor confidential environments or strict data privacy, **exclusively use a local Ollama endpoint** (e.g., `qwen2.5:7b` via local Open WebUI). This prevents DOM data, proprietary class names, or sensitive layouts from leaving your secure network. Cloud providers (OpenAI/Anthropic) are suitable only if testing environments are public or data exfiltration is not a concern.\n\n---\n\n## ✨ Features\n\n*   **Seamless Proxy Interceptor**: Transparently wraps Playwright, catching native timeouts without test logic modification.\n*   **Proactive DOM Caching**: Records \"Known Good\" DOM snapshots before successful actions. When an element breaks, the AI compares historical and current DOMs to identify altered properties.\n*   **Healed Suggestion File**: Generates a `*.spec-healed.ts` file with suggested locator fixes alongside your original spec file for you to review and adopt.\n*   **Healed Suggestion File**: Generates a `*.spec-healed.ts` file with suggested locator fixes alongside your original spec file for you to review and adopt.\n*   **Page Object Model (POM) Parsing**: Dynamically parses the JavaScript execution stack. If a locator fails in a POM class (e.g., `login.page.ts`), the AI Healer traces the boundary and rewrites the POM file natively.\n*   **Top-7 Fallback Engine**: The AI returns the top 7 most confident locators, prioritized by confidence. The Healer executes these sequentially, allowing smaller models multiple attempts without test suite failure.\n*   **Syntactical Sanitization**: A heuristic regex scrubber automatically corrects SASS-like pseudo-class hallucinations (e.g., `tag(class1 class2)` to `tag.class1.class2`) common with quantized local models. Includes a case-insensitive CSS fallback that retries selectors in lowercase when the original casing fails.\n*   **Spec Rewrite Proposals**: Creates an updated `spec-healed.ts` file with proposed locator replacements. Review the suggestions and copy them into your spec files to permanently fix your tests.\n\n---\n\n## 🛠 Usage\n\n### 1. Install the package:\n\n```bash\nnpm install -D @axeforging/playwright-smart-locators\n```\n\n### 2. Wrap your `playwright.config.ts`:\n\nImport the custom auto-healer and configure your Open WebUI or OpenAI-compatible endpoint:\n\n```typescript\nimport { defineConfig, devices } from '@playwright/test';\n\nexport default defineConfig({\n    reporter: [\n        ['html'],\n        ['@axeforging/playwright-smart-locators/dist/reporter'] // Required for Auto-Spec Rewriting\n    ],\n    use: {\n        enableAutoHeal: !process.env.CI, // Enable in local dev, disable in CI/CD\n        enableAutoHeal: !process.env.CI, // Enable in local dev, disable in CI/CD\n        aiModel: 'qwen2.5:7b', // Local Ollama model for maximum privacy\n        aiPipeUrl: process.env.AI_API_URL, // e.g., Open WebUI, OpenAI, or Anthropic endpoint\n        aiAdminKey: process.env.AI_API_KEY, // e.g., 'sk-...'\n        aiProvider: 'openai' // 'openai' (default) or 'anthropic'\n    }\n});\n```\n\n### 3. Import `test` from the library:\n\nReplace standard Playwright `@playwright/test` imports in your spec files:\n\n```diff\n- import { test, expect } from '@playwright/test';\n+ import { test, expect } from '@axeforging/playwright-smart-locators';\n```\n\n---\n\n## 🛠 Example Project\n\nThe repository includes an `example` testing suite demonstrating Auto-Healer capabilities. These tests target [github.com/axeforging/tacomex-8bit-shop](https://github.com/AxeForging/tacomex-8bit-shop).\n\nTo run the examples:\n\n1.  Navigate to the example directory: `cd example`\n2.  Install dependencies: `npm install`\n3.  Run the tests: `npx playwright test`\n\n### Example Scenarios\n\nThe example includes 6 intentionally broken tests that the AI will auto-heal at runtime:\n\n*   **`tests/example.spec.ts`**: 3 standard procedural Playwright tests.\n*   **`tests/pom.spec.ts`**: 3 tests using Page Object Model (POM), demonstrating how the Healer rewrites `pages/login.page.ts` natively.\n\n---\n\n## 🚀 Execution Example (Local Development)\n\nDuring local development, `playwright-smart-locators` provides real-time console feedback on the healing process, detailing actions taken and summarizing generated suggestion files:\n\n```plaintext\nRunning 6 tests using 6 workers\n\n🤖 [AI Auto-Heal] Intercepted failure on: locator('text=\"Sign In\"')\n✅ [AI Auto-Heal] Fixed! Resuming with: .navbar__login-btn\n  ✓  2 tests/pom.spec.ts:11:9 › POM Auto-Healing Scenarios › Scenario 1: Text changed (POM Login Button) (5.0s)\n\n...\n\n  6 passed (7.7s)\n\n=========================================\n🧠 Smart Locators Summary\n=========================================\nTotal Locators Healed: 6\n✨ Generated auto-healed spec: /your-project/example/pages/login.page-healed.ts\n✨ Generated auto-healed spec: /your-project/example/tests/example.spec-healed.ts\n```\n\nReview the generated `-healed.ts` files, verify the suggested locators are correct, and adopt them into your spec files.\n\n---\n\n## 🧠 The \"Line of Thought\" Lifecycle\n\n```mermaid\nsequenceDiagram\n    participant Test as Playwright Suite\n    participant Proxy as Smart Proxy\n    participant Cache as DOM Cache\n    participant LLM as AI (Local/Cloud)\n    participant Disk as File System\n\n    Note over Test, Disk: 🟢 Record Phase (Green Test)\n    Test-\u003e\u003eProxy: Successful locator action\n    Proxy-\u003e\u003eCache: Save \"Known Good\" DOM snapshot\n\n    Note over Test, Disk: 🔴 Intercept Phase (Broken Test)\n    Test-\u003e\u003eProxy: Execute locator (element changed/missing)\n    Proxy--xTest: Intercept TimeoutError\n    \n    Note over Proxy, LLM: 🧠 Contextual Evaluation \u0026 Resolution\n    Proxy-\u003e\u003eCache: Retrieve cached \"Known Good\" DOM\n    Proxy-\u003e\u003eLLM: Transmit Payload (Broken Locator + Cached DOM + Current DOM)\n    LLM--\u003e\u003eProxy: Return Top 7 Resilient Locators (Priority Ranked)\n    \n    Note over Test, Disk: ✨ Execution \u0026 Rewrite\n    Proxy-\u003e\u003eTest: Try healed locator \u0026 continue test run\n    Proxy-\u003e\u003eDisk: Generate *.spec-healed.ts suggestion file for review\n    Proxy-\u003e\u003eTest: Try healed locator \u0026 continue test run\n    Proxy-\u003e\u003eDisk: Generate *.spec-healed.ts suggestion file for review\n```\n\n1.  **Record Phase**: During a successful test run, the library caches a stripped \"Known Good\" DOM snapshot locally (e.g., `.smart-locators-cache.json`) before successful locator actions.\n2.  **Intercept Phase**: If an element changes (e.g., `\u003cbutton class=\"btn-primary\"\u003e` to `\u003cbutton class=\"btn-accent\"\u003e`), the proxy intercepts Playwright's `TimeoutError`.\n3.  **Contextual Evaluation**: The proxy sends a payload to the LLM with the **Broken Locator**, **Known Good DOM**, and **Current Broken DOM**.\n4.  **Resolution**: The LLM evaluates DOM differences to identify the element and calculates the most resilient new CSS selector based on a strict priority hierarchy.\n5.  **Execution \u0026 Suggestion**: The library tries the healed locator to continue your test session, and the reporter generates a `-healed.ts` suggestion file for you to review before adopting the fix.\n5.  **Execution \u0026 Suggestion**: The library tries the healed locator to continue your test session, and the reporter generates a `-healed.ts` suggestion file for you to review before adopting the fix.\n\n---\n\n## 🧪 Model Experiments \u0026 Insights\n\nOur goal was a model providing 100% syntactical CSS accuracy on dense React DOMs with minimal overhead.\n\n*   `llama3.2:3b` - **Failed**: High hallucination rates on complex DOMs, generating fake nested layouts.\n*   `gpt-oss:20b` - **Excellent**: Flawless operation without DOM caching restrictions, but financially expensive and GPU-intensive.\n*   `qwen2.5-coder:1.5b` and `qwen2.5:3b-instruct` - **Failed**: Small models struggled with strict JSON output, often hallucinating invalid CSS syntax (e.g., `.class1(class2)`).\n*   `qwen2.5:7b` - **Optimal**: With Proactive DOM Caching and strict JSON prompt enforcement, this lightweight model achieved 100% perfect healing, offering premium intelligence at a fraction of the cost of 20B+ models.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxeforging%2Fplaywright-smart-locators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxeforging%2Fplaywright-smart-locators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxeforging%2Fplaywright-smart-locators/lists"}