Package Exports
- playwright-genie-ai
- playwright-genie-ai/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (playwright-genie-ai) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐ง Playwright Genie AI
AI-powered Playwright test generator that creates test scripts from natural language scenarios.
๐ Features
- Natural Language Testing: Describe your test scenario in plain English
- Multiple AI Models: Support for GPT-4, GPT-3.5, and local Ollama models
- Automatic Test Generation: Creates complete Playwright
.spec.tsfiles - Instant Execution: Option to run tests immediately after generation
- Smart Selectors: Uses best practices for element selection
- NPM CLI Tool: Easy to install and use anywhere
๐ฆ Installation
Global Installation (Recommended)
npm install -g playwright-genie-aiOne-time Usage
npx playwright-genie-ai --url <url> --scenario "<scenario>"Prerequisites
- Node.js 16.0.0 or higher
- npm 7.0.0 or higher
โก Quick Start
Install the tool:
npm install -g playwright-genie-ai
Install Playwright (if not already installed):
npx playwright installSet up your API key:
echo "OPENAI_API_KEY=your_api_key_here" > .env
Generate and run your first test:
playwright-genie-ai \ --url "https://www.saucedemo.com/" \ --scenario "Login with standard_user and secret_sauce, then add first item to cart" \ --run
โ๏ธ Setup
Install Playwright (if not already installed):
npx playwright installSet up environment variables:
cp .env.example .envEdit
.envand add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_hereFor Ollama (local AI), ensure Ollama is running on
localhost:11434or set:OLLAMA_BASE_URL=http://localhost:11434
๐ฏ Usage
Basic Usage
playwright-genie-ai --url "https://example.com" --scenario "Login with valid credentials"Advanced Usage
playwright-genie-ai \
--url "https://www.saucedemo.com/" \
--scenario "Login as standard_user with password secret_sauce, sort by Name (Z to A), and add the first item to cart" \
--model gpt-4 \
--output "saucedemo-login-test" \
--runCLI Options
| Option | Description | Required | Default |
|---|---|---|---|
--url <url> |
Target website URL | โ | - |
--scenario <text> |
Natural language test description | โ | - |
--model <model> |
AI model (gpt-4, gpt-3.5, ollama) |
โ | gpt-4 |
--output <filename> |
Custom output filename (without extension) | โ | Timestamped |
--run |
Run the test immediately after generation | โ | false |
๐งช Example Test Cases
E-commerce Login Flow
playwright-genie-ai \
--url "https://www.saucedemo.com/" \
--scenario "Login as standard_user with password secret_sauce, sort by Name (Z to A), and add the first item to cart" \
--runForm Submission
playwright-genie-ai \
--url "https://httpbin.org/forms/post" \
--scenario "Fill out the form with name 'John Doe', email 'john@example.com', and submit it"Navigation Test
playwright-genie-ai \
--url "https://playwright.dev" \
--scenario "Navigate to the docs section and search for 'selectors'"๐ค Supported AI Models
OpenAI Models
- GPT-4: Most capable, best for complex scenarios
- GPT-3.5: Faster and cheaper, good for simple tests
Local Models (Ollama)
- CodeLlama: Free local AI model for code generation
- No API key required, runs entirely offline
๐ Generated Files
Tests are saved in the ./tests/ directory with the following naming:
- Custom name:
<your-name>.spec.ts - Auto-generated:
generated-test-YYYY-MM-DDTHH-mm-ss.spec.ts
๐ง Development
Building from Source
git clone https://github.com/sxtyxmm/playwright-genie-ai.git
cd playwright-genie-ai
npm install
npm run buildDevelopment Mode
npm run dev -- --url "https://example.com" --scenario "Your test scenario"Project Structure
playwright-genie-ai/
โโโ src/
โ โโโ index.ts # CLI entry point
โ โโโ generator.ts # AI model integration
โ โโโ fileWriter.ts # Test file creation
โ โโโ runner.ts # Test execution
โโโ tests/ # Generated test files
โโโ dist/ # Compiled JavaScript
โโโ package.json
โโโ tsconfig.json
โโโ README.md๐ How It Works
- Input Parsing: CLI accepts URL and scenario description
- AI Generation: Sends structured prompt to selected AI model
- Code Generation: AI creates complete Playwright test code
- File Writing: Saves test to
/testsdirectory - Optional Execution: Runs test with Playwright if
--runflag is used
๐ ๏ธ Troubleshooting
Common Issues
Missing OpenAI API Key
Error: OPENAI_API_KEY environment variable is requiredSolution: Add your API key to .env file
Playwright Not Installed
Playwright is not installed. Please run: npx playwright installSolution: Run npx playwright install
Generated Test Fails
- Check if the website structure has changed
- Try a more specific scenario description
- Use
--model gpt-4for better accuracy
Debug Mode
Add DEBUG=1 to see detailed logs:
DEBUG=1 playwright-genie-ai --url "..." --scenario "..."๐ค Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ License
MIT License - see LICENSE file for details.
๐ฎ Future Features
- Auto-detect selectors using page inspection
- Support for multi-step test scenarios
- Integration with ZeroStep's
ai()helper - Test maintenance and updating capabilities
- Visual regression testing support
- Custom AI model endpoints
๐ Support
- ๐ Report Issues
- ๐ฌ Discussions
- ๏ฟฝ NPM Package
- ๐ Documentation
๐ NPM Stats
Made with โค๏ธ by the Playwright Genie AI team