# Playwright Test Agent MCP Server (`bronze_quarterback/playwright-test-agent-mcp`) Actor

Generate, run, and debug Playwright E2E tests through natural language. Run specs, analyze failures, generate new tests, and list test files.

- **URL**: https://apify.com/bronze\_quarterback/playwright-test-agent-mcp.md
- **Developed by:** [Segun Zubair](https://apify.com/bronze_quarterback) (community)
- **Categories:** AI, Developer tools
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$29.00/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month. You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#rental-actors

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Playwright Test Agent -- MCP Server

Generate, run, and debug Playwright tests using Claude.

### Quick Start (2 minutes)

#### Prerequisites

- Python 3.11+
- Node.js 18+
- Playwright browsers installed

#### Install

```bash
## Clone or download the server
cd playwright-test-agent

## Install Python dependencies
pip install -r requirements.txt

## Install Playwright and browsers
npm install @playwright/test
npx playwright install chromium
```

#### Configure Claude Desktop

Add to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "playwright-test-agent": {
      "command": "python",
      "args": ["src/server.py"],
      "cwd": "/path/to/playwright-test-agent",
      "env": {
        "PROJECT_PATH": "/path/to/your/playwright/project"
      }
    }
  }
}
```

Restart Claude Desktop. You should see "playwright-test-agent" in the MCP server list.

### What It Does

Connect Claude to your Playwright test suite. Ask it to run tests, generate new ones from plain English, pull up the latest results, or debug flaky failures -- all from the chat window.

### Example Use Cases

1. "Generate a Playwright test for the login page at localhost:3000/login"
2. "Run my test suite and tell me which tests failed and why"
3. "This test is flaky -- debug it and suggest a fix"
4. "List all test files in my project"
5. "What were the results of my last test run?"

### Available Tools

| Tool | Description | Parameters |
|------|-------------|------------|
| `run_test_file` | Execute a Playwright spec file and return structured results (pass/fail, duration, failure details) | `test_file` (required), `project` (optional -- browser project name) |
| `generate_test` | Generate a Playwright TypeScript test from a natural language description | `description` (required), `base_url` (optional) |
| `get_test_results` | Retrieve and summarize results from the last Playwright test run | `results_dir` (optional) |
| `debug_failure` | Analyze a test failure with root cause identification and suggested fixes | `test_file` (required), `failure_message` (required), `screenshot_path` (optional) |
| `list_test_files` | List all Playwright spec files (`.spec.ts`, `.spec.js`, `.test.ts`, `.test.js`) in the project | `test_dir` (optional) |

### Configuration

All configuration is through environment variables:

| Variable | Description | Default |
|----------|-------------|---------|
| `PROJECT_PATH` | Path to your Playwright project (where `playwright.config.ts` lives) | `.` (current directory) |
| `OPENAI_API_KEY` | API key for LLM features (test generation, failure debugging) | -- (LLM features disabled if unset) |
| `OPENAI_BASE_URL` | OpenAI-compatible API base URL | `https://api.openai.com/v1` |
| `OPENAI_MODEL` | Model for test generation and debugging | `gpt-4o` |

**Note:** The `generate_test` and `debug_failure` tools require `OPENAI_API_KEY` to be set. All other tools work without it.

### Docker Usage

You can also run the server in a container:

```bash
docker build -t playwright-test-agent .
docker run -i --rm \
  -e PROJECT_PATH=/tests \
  -v /path/to/your/tests:/tests \
  playwright-test-agent
```

### Troubleshooting

- **"npx not found"** -- Ensure Node.js is installed and `npx` is in your PATH
- **Browser not installed** -- Run `npx playwright install chromium`
- **Test generation returns an error** -- Verify `OPENAI_API_KEY` is set in your env config
- **Timeout errors** -- Increase the Playwright timeout in your `playwright.config.ts`

### Pricing

**$29 -- one-time purchase.** Includes the full MCP server with all 5 tools: test execution, test generation, results retrieval, failure debugging, and spec file listing. Runs locally on your machine -- no ongoing fees.

### License

MIT

# Actor input Schema

## `projectPath` (type: `string`):

Root directory of the project containing Playwright tests. Defaults to current directory.

## `openaiApiKey` (type: `string`):

OpenAI API key for test generation and failure debugging features. Optional — only needed for generate\_test and debug\_failure tools.

## `openaiModel` (type: `string`):

OpenAI model to use for LLM features. Defaults to gpt-4o.

## Actor input object example

```json
{
  "projectPath": ".",
  "openaiModel": "gpt-4o"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("bronze_quarterback/playwright-test-agent-mcp").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("bronze_quarterback/playwright-test-agent-mcp").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call bronze_quarterback/playwright-test-agent-mcp --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bronze_quarterback/playwright-test-agent-mcp"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/T3w7aQObMWuSr1d6p/builds/bCl1N6Ub4ORIybpMY/openapi.json
