Submit natural language prompts to an AI chatbot, which will use a browser through an MCP (Model Context Protocol) server to perform actions and generate Playwright tests automatically.
- π€ AI-Powered Test Generation: Use natural language to describe what you want to test
- π Playwright Integration: Automatically generates valid Playwright test code
- π Browser Automation: Real-time browser control through MCP server
- π‘ WebSocket Updates: Live feedback as actions are executed
- π¨ Beautiful UI: Clean, modern web interface
- π§ Configurable: Support for headless/headed browser modes
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Web Client βββββΆβ Express βββββΆβ OpenAI API β
β (Frontend) β β Server β β (GPT-4) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β MCP Server β
β (Playwright) β
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Browser β
β (Chromium) β
βββββββββββββββββββ
- Node.js (v18 or higher)
- OpenAI API key
- Modern web browser
-
Navigate to the project directory:
cd playwright-ai-integration -
Install dependencies:
npm install
-
Install Playwright browsers:
npm run install-browsers
-
Set up environment variables:
cp .env.example .env
Edit
.envand add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_here
-
Start the main server:
npm start
-
Open your browser and navigate to:
http://localhost:3000
-
Start a Session:
- Enter your OpenAI API key (if not set in environment)
- Click "Start Session" to initialize the MCP server
-
Submit a Prompt:
- Enter a natural language description of what you want to test
- Examples:
- "Go to google.com and search for playwright testing"
- "Navigate to github.com, click on the search box, and search for microsoft/playwright"
- "Open example.com and take a screenshot of the page"
-
Watch the Magic:
- See real-time updates as actions are executed
- View the generated Playwright test code
- Copy the test to use in your project
-
Basic Navigation:
Go to example.com and take a screenshot -
Form Interaction:
Navigate to httpbin.org/forms/post, fill in the customer name field with "John Doe", and submit the form -
Search Functionality:
Go to google.com, search for "playwright testing", and click on the first result -
Complex Workflows:
Open github.com, click on sign in, wait for the login form to appear, and take a screenshot
The MCP server provides the following tools for browser automation:
launch_browser- Launch a new browser instancenavigate_to- Navigate to a specific URLclick_element- Click on elements using CSS selectorsfill_input- Fill input fields with textwait_for_element- Wait for elements to appeartake_screenshot- Capture screenshotsget_page_content- Get page informationgenerate_test- Generate Playwright test codeclose_browser- Close the browser instance
playwright-ai-integration/
βββ src/
β βββ server.js # Express server with WebSocket support
β βββ ai-integration.js # AI service for processing prompts
β βββ mcp-server.js # MCP server for browser automation
βββ public/
β βββ index.html # Web interface
βββ tests/
β βββ example.spec.js # Example generated test
βββ package.json
βββ playwright.config.js
βββ README.md
npm run devThis starts the server with file watching enabled.
npm run mcp-servernpm testOr with UI mode:
npm run test:uiPOST /api/start-session- Initialize AI integration sessionPOST /api/process-prompt- Process a natural language promptGET /api/session-status- Get current session statusPOST /api/stop-session- Stop the current session
OPENAI_API_KEY- Your OpenAI API key (required)PORT- Server port (default: 3000)HEADLESS- Run browser in headless mode (default: false)
The project includes a playwright.config.js file with optimized settings for:
- Multiple browser support (Chrome, Firefox, Safari)
- Screenshot and video recording on failures
- HTML reporting
- Trace collection
-
"MCP server not connected" error:
- Ensure Node.js is properly installed
- Check that no other process is using the required ports
- Restart the session
-
"Browser not launched" error:
- Run
npm run install-browsersto install Playwright browsers - Check system permissions for browser execution
- Run
-
OpenAI API errors:
- Verify your API key is correct and has sufficient credits
- Check your OpenAI API usage limits
-
Element not found errors:
- The AI might generate selectors that don't exist on the target page
- Try more specific prompts or different selector strategies
Set environment variable for verbose logging:
DEBUG=* npm start- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
- Playwright for browser automation
- OpenAI for AI capabilities
- Model Context Protocol for the integration framework
