smart-playwright-nlp
v1.0.0
Published
Natural language and text-based locator wrapper for Playwright
Maintainers
Readme
smart-playwright-nlp 🚀
An AI-assisted natural language and text-based locator wrapper for Playwright. Author end-to-end tests using intuitive, human-readable instructions backed by a robust, multi-tier locator fallback engine.
🌟 Key Features
- 📝 Natural Language Parsing: Powered by lightweight deterministic tokenization (
compromiseNLP), eliminating heavy API latency. - 🛡️ Multi-Tier Smart Locators: Cascades through accessibility roles, data attributes, placeholders, labels, and text-proximity rules to avoid test flakiness.
- 📦 Dual Module Export: Ships fully compiled with clean ESM (
.mjs) and CommonJS (.js) paths with baked-in TypeScript declaration maps (.d.ts). - ⚡ Zero-Config Playwright Integration: Drop it straight into your current standard
@playwright/testrunner configuration hooks.
💾 Installation
Ensure you have @playwright/test installed in your host project repository:
npm install smart-playwright-nlp
Usage
import { test } from '@playwright/test';
import { SmartWrapper } from 'smart-playwright-nlp';
test('End-to-End Core E-Commerce Purchase Flow', async ({ page }) => {
const ai = new SmartWrapper(page);
// 1. Navigation Commands
await ai.execute("Navigate to '[https://example.com/login](https://example.com/login)'");
// 2. Interactive Form Actions (First quotes = value, Second quotes = target)
await ai.execute("Type 'test_admin' into 'Username'");
await ai.execute("Type 'SecurePassword123' into 'Password'");
await ai.execute("Click the 'Sign In' button");
// 3. Smart Web-First Assertions
await ai.execute("Verify that the text 'Welcome Back' is visible");
await ai.execute("Verify that url contains '/dashboard'");
});
