JSPM

playwright-genie-ai

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q18407F
  • License MIT

AI-powered Playwright test generator that creates test scripts from natural language scenarios

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.ts files
  • 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

npm install -g playwright-genie-ai

One-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

  1. Install the tool:

    npm install -g playwright-genie-ai
  2. Install Playwright (if not already installed):

    npx playwright install
  3. Set up your API key:

    echo "OPENAI_API_KEY=your_api_key_here" > .env
  4. 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

  1. Install Playwright (if not already installed):

    npx playwright install
  2. Set up environment variables:

    cp .env.example .env

    Edit .env and add your OpenAI API key:

    OPENAI_API_KEY=your_openai_api_key_here

    For Ollama (local AI), ensure Ollama is running on localhost:11434 or 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" \
  --run

CLI 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" \
  --run

Form 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"
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 build

Development 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

  1. Input Parsing: CLI accepts URL and scenario description
  2. AI Generation: Sends structured prompt to selected AI model
  3. Code Generation: AI creates complete Playwright test code
  4. File Writing: Saves test to /tests directory
  5. Optional Execution: Runs test with Playwright if --run flag is used

๐Ÿ› ๏ธ Troubleshooting

Common Issues

Missing OpenAI API Key

Error: OPENAI_API_KEY environment variable is required

Solution: Add your API key to .env file

Playwright Not Installed

Playwright is not installed. Please run: npx playwright install

Solution: Run npx playwright install

Generated Test Fails

  • Check if the website structure has changed
  • Try a more specific scenario description
  • Use --model gpt-4 for better accuracy

Debug Mode

Add DEBUG=1 to see detailed logs:

DEBUG=1 playwright-genie-ai --url "..." --scenario "..."

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. 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

๐Ÿ“Š NPM Stats

npm version npm downloads License: MIT


Made with โค๏ธ by the Playwright Genie AI team