使用说明
Selenium MCP服务器
一键安装
第一个使用Selenium Grid实现真正并行浏览器自动化的MCP服务器。
当其他浏览器MCP服务器运行单个浏览器实例时,Selenium MCP服务器连接到Selenium Grid 大规模并行勘探 --启动10、20或100个浏览器会话,同时探索您的整个应用程序。
为什么这个过度剧作家MCP?
| 功能 | 剧作家MCP | Selenium MCP服务器 |
|---|---|---|
| 平行性 | 单一浏览器,共享上下文 | 真正的并行:具有无限节点的网格 |
| 扩展 | 受限于单个浏览器 | 水平可扩展--根据需要添加节点 |
| 孤立 | 客户端之间的共享状态 | 每个会话完全隔离 |
| 多浏览器 | 一次一个 | 同时使用Chrome+Firefox+Edge |
| 基础设施 | 简单 | Docker编写就绪 |
| AI代理工作流程 | 基础 | 规划师→ 发电机→ Healer管道 |
非常适合: 需要快速探索大型应用程序、跨浏览器测试和大规模企业自动化的AI代理。
快速开始
1.安装
# Install globally
npm install -g selenium-ai-agent
# Or run directly with npx (no install needed)
npx selenium-ai-agent
2.配置您的MCP客户端
自动安装 (克劳德桌面、光标或Windsurf):
npx selenium-ai-agent install claude-desktop
npx selenium-ai-agent install cursor
npx selenium-ai-agent install windsurf
克劳德代码:
claude mcp add selenium-mcp -- npx selenium-ai-agent
Manual config (click to expand)
克劳德桌面 (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"selenium-mcp": {
"command": "npx",
"args": ["selenium-ai-agent"]
}
}
}
光标 (.cursor/mcp.json):
{
"mcpServers": {
"selenium-mcp": {
"command": "npx",
"args": ["selenium-ai-agent"]
}
}
}
GitHub Copilot (.vscode/mcp.json):
{
"servers": {
"selenium-mcp": {
"command": "npx",
"args": ["selenium-ai-agent"],
"type": "stdio"
}
}
}
看 MCP客户端设置 适用于所有6个客户端(Claude Code、Claude Desktop、Cursor、Copilot、Cline、Windsurf)。
3.试试看!
"Navigate to https://example.com and take a screenshot"
聊天示例
配置MCP服务器后,将这些提示复制粘贴到您的AI助手中。
导航和屏幕截图
你说:
首选https://practiceautomatedtesting.com并截图
发生了什么:
navigate_to--在本地Chrome浏览器中打开URLtake_screenshot--捕获整个页面
AI回应:
我导航到practiceautomatedtesting.com并截图。该页面显示了一个带有导航栏、特色产品部分和页脚的电子商务店面。
探索和创建测试计划
你说:
探索结账流程https://practiceautomatedtesting.com并制定测试计划
发生了什么:
planner_setup_page--导航到站点,捕获初始页面快照planner_explore_page--浏览主页,发现产品链接planner_explore_page--跟随产品→ 加入购物车→ 购物车页面流planner_explore_page--继续执行签出、捕获表单字段和验证planner_save_plan--将测试计划写入markdown文件
AI回应:
我浏览了4页的结账流程,并将测试计划保存到
test-plans/checkout-flow.md该计划涵盖了6个测试场景,包括添加到购物车、结账表单验证和成功订单。在生成测试代码之前,请先查看计划。
生成WebdriverIO测试
你说:
在以下位置为登录流生成WebdriverIO测试https://practiceautomatedtesting.com
发生了什么:
- 如果需要,初始化项目--
npm init,安装@wdio/cli,创建wdio.conf.ts generator_setup_page--打开网站framework: "webdriverio-ts",开始录制navigate_to→input_text→click_element→verify_text_visible--与登录表单交互stop_recording--结束录制会话generator_write_test--生成a.test.ts记录步骤中的文件
AI回应:
我设置了一个WebdriverIO项目,记录了登录流程,并生成了
tests/login.test.ts:describe('Login Flow', () => { it('should log in with valid credentials', async () => { await browser.url('https://practiceautomatedtesting.com/login'); await $('[data-testid="email"]').setValue('user@example.com'); await $('[data-testid="password"]').setValue('password123'); await $('[data-testid="login-button"]').click(); await expect($('[data-testid="welcome-message"]')).toBeDisplayed(); }); });运行方式:
npx wdio run wdio.conf.ts
生成剧作家测试
你说:
在以下位置为产品搜索功能创建Playwright测试https://practiceautomatedtesting.com
发生了什么:
- 如果需要,初始化项目--
npm init,安装@playwright/test,运行npx playwright install generator_setup_page--打开网站framework: "playwright-js",开始录制- 导航搜索功能并与之交互
stop_recording→generator_write_test--生成Playwright测试文件
AI回应:
我建立了一个剧作家项目,记录了搜索流程,并生成了
tests/product-search.spec.js:const { test, expect } = require('@playwright/test'); test('should search for products and display results', async ({ page }) => { await page.goto('https://practiceautomatedtesting.com/products'); await page.locator('[data-testid="search-input"]').fill('laptop'); await page.locator('[data-testid="search-button"]').click(); await expect(page.locator('[data-testid="results-count"]')).toBeVisible(); });运行方式:
npx playwright test
生成Selenium Python(pytest)测试
你说:
为注册表生成pytest Selenium测试https://practiceautomatedtesting.com
发生了什么:
- 如果需要,设置项目--创建
venv,安装selenium和pytest通过pip generator_setup_page--打开网站framework: "selenium-python-pytest",开始录制- 浏览并填写注册表
stop_recording→generator_write_test--生成pytest文件
AI回应:
我用selenium和pytest建立了一个Python虚拟环境,记录了注册流程,并生成了
tests/test_registration.py:class TestRegistration: def test_register_new_user(self, driver): driver.get("https://practiceautomatedtesting.com/register") driver.find_element(By.CSS_SELECTOR, '[data-testid="name"]').send_keys("Jane Doe") driver.find_element(By.CSS_SELECTOR, '[data-testid="email"]').send_keys("jane@example.com") driver.find_element(By.CSS_SELECTOR, '[data-testid="password"]').send_keys("SecurePass123!") driver.find_element(By.CSS_SELECTOR, '[data-testid="register-button"]').click() assert "Welcome" in WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-testid="success-message"]')) ).text运行方式:
pytest tests/test_registration.py -v
生成机器人框架测试
你说:
在以下位置为联系人表单生成机器人框架测试https://practiceautomatedtesting.com
发生了什么:
- 如果需要,设置项目--创建
venv,安装robotframework和robotframework-seleniumlibrary通过pip generator_setup_page--打开网站framework: "robot-framework",开始录制- 导航到联系人页面并填写表格
stop_recording→generator_write_test--生成a.robot文件
AI回应:
我设置了一个Robot Framework环境,记录了联系人表单流,并生成了
tests/contact_form.robot:*** Settings *** Library SeleniumLibrary *** Variables *** ${URL} https://practiceautomatedtesting.com/contact *** Test Cases *** Submit Contact Form With Valid Data Open Browser ${URL} chrome Input Text css=[data-testid="name"] Jane Doe Input Text css=[data-testid="email"] jane@example.com Input Text css=[data-testid="message"] Hello, I have a question about your products. Click Element css=[data-testid="submit-button"] Wait Until Element Is Visible css=[data-testid="success-message"] Element Should Contain css=[data-testid="success-message"] Thank you [Teardown] Close Browser运行方式:
robot tests/contact_form.robot
运行测试并修复故障
你说:
运行我的测试并修复任何故障
发生了什么:
healer_run_tests--执行测试套件;3次测试中有1次失败healer_debug_test--分析故障(过时的选择器#old-login-btn未找到)healer_inspect_page--打开页面以查找正确的选择器healer_fix_test--将选择器更新为[data-testid="login-button"]healer_run_tests--重新运行套房;所有3项测试均通过
AI回应:
我运行了你的测试套件,发现了一个失败:选择器
#old-login-btn未找到。我查看了页面,并将其更新为[data-testid="login-button"],并重新运行-- 3通过,0失败.
并行网格探索
需要 网格设置.
你说:
浏览整个网站https://practiceautomatedtesting.com同时使用4个浏览器
发生了什么:
parallel_explore--启动4个网格会话,同时探索主页、产品、购物车和帐户exploration_merge--将所有4个结果合并到一个站点地图中planner_generate_plan--从合并的数据中生成全面的测试计划
AI回应:
我在Selenium Grid上使用4个浏览器并行浏览了该网站:
会话 节 页 元素 1 主页 3 42 2 产品 8 156 3 购物车和结账 4 67 4 帐户和身份验证 3 38 18个独特页面,303个元素 在大约12秒内发现。测试计划已保存到
test-plans/full-site-plan.md.
Generator支持14个框架:
webdriverio-ts,playwright-js,selenium-python-pytest,robot-framework,selenium-java-maven,以及 更多示例1至6适用于本地浏览器。只有并行探索需要Selenium Grid。
基于Selenium Grid的并行探索
在几秒钟内浏览整个应用程序,而不是几分钟:
启动网格
git clone https://github.com/learn-automated-testing/selenium_agent.git
cd selenium_agent/selenium-grid
docker-compose up -d
# Verify Grid is running
open http://localhost:4444 # Grid console
使用网格进行配置
{
"mcpServers": {
"selenium-mcp": {
"command": "npx",
"args": ["selenium-ai-agent"],
"env": {
"SELENIUM_GRID_URL": "http://localhost:4444"
}
}
}
}
并行探索
"Explore the e-commerce site at https://practiceautomatedtesting.com in parallel —
check the homepage, products, cart, and checkout sections simultaneously"
代理将在您的网格上启动4个浏览器会话,并一次浏览所有部分。
// What happens behind the scenes:
parallel_explore({
baseUrl: "https://myshop.com",
targets: [
{ url: "/", label: "Homepage", maxPages: 10 },
{ url: "/products", label: "Catalog", maxPages: 20 },
{ url: "/cart", label: "Cart Flow", maxPages: 5 },
{ url: "/account", label: "User Account", maxPages: 10 }
]
})
// → 4 browsers explore simultaneously
// → Results merged and deduplicated
// → Complete site map in one call
随时扩大规模:
docker-compose up -d --scale chrome-node=10
73工具
网格和并行执行
| 工具 | 说明 |
|---|---|
grid_status |
检查网格运行状况、节点和容量 |
grid_start |
启动Docker编写网格 |
grid_stop |
停止Docker编写网格 |
grid_scale |
向上/向下缩放网格节点 |
session_create |
在Grid上创建浏览器会话 |
session_select |
切换活动会话 |
session_list |
列出所有网格会话 |
session_destroy |
清理会话 |
session_destroy_all |
清理所有会话 |
parallel_explore |
同时浏览多个URL |
parallel_execute |
跨会话并行运行任务 |
exploration_merge |
结合勘探成果 |
exploration_diff |
比较探索 |
planner_generate_plan |
从勘探中生成测试计划 |
导航
navigate_to · go_back · go_forward · refresh_page
页面分析
capture_page · take_screenshot
元素交互
click_element · hover_element · select_option · drag_drop
输入
input_text · key_press · file_upload
老鼠
mouse_move · mouse_click · mouse_drag
验证
verify_element_visible · verify_text_visible · verify_value · verify_list_visible
浏览器管理
wait_for · execute_javascript · dialog_handle · console_logs · network_monitor · resize_window · pdf_generate
标签页
tab_list · tab_select · tab_new · tab_close
会话
close_browser · reset_session · set_stealth_mode
录制
start_recording · stop_recording · recording_status · clear_recording
批次
batch_execute
AI代理工具
| 代理 | 工具 |
|---|---|
| 规划师 | planner_setup_page, planner_explore_page, planner_save_plan |
| 发电机 | generator_setup_page, generator_read_log, generator_write_test, generator_write_seed, generator_save_spec, generator_read_spec |
| 治愈者 | healer_run_tests, healer_debug_test, healer_fix_test, healer_inspect_page, browser_generate_locator |
| 分析器 | analyzer_setup, analyzer_import_context, analyzer_scan_product, analyzer_build_risk_profile, analyzer_save_profile, analyzer_generate_documentation |
AI测试代理
带有人工审查门的完整测试流程:
┌─────────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────────┐
│ Analyzer │───▶│ Planner │───▶│ Generator │───▶│ Healer │
│ (risk profile) │ │ (test plan) │ │ (test code) │ │(fix tests) │
└─────────────────┘ └─────────────┘ └─────────────┘ └────────────┘
│ │
human review human review
看 聊天示例 以上为涵盖每个阶段的完整复制粘贴提示。
配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
SELENIUM_GRID_URL |
-- | 网格中心URL(启用并行功能) |
SELENIUM_BROWSER |
chrome |
要使用的浏览器(chrome, firefox, edge) |
SELENIUM_HEADLESS |
false |
在无头模式下运行浏览器 |
SELENIUM_TIMEOUT |
30000 |
默认超时时间(毫秒) |
SE_AVOID_STATS |
-- | 设置为 true 禁用Selenium使用统计信息 |
本地浏览器(无网格)
没有网格也能工作——只是不要设置 SELENIUM_GRID_URL:
{
"mcpServers": {
"selenium-mcp": {
"command": "npx",
"args": ["selenium-ai-agent"]
}
}
}
Docker Compose
包括 docker-compose.yml 为您提供生产就绪的网格:
services:
selenium-hub:
image: selenium/hub:4.40.0
ports:
- "4444:4444"
chrome-node:
image: selenium/node-chrome:4.40.0
deploy:
replicas: 4 # 4 Chrome browsers
firefox-node:
image: selenium/node-firefox:4.40.0
deploy:
replicas: 1 # 1 Firefox browser
项目结构
selenium_agent/
├── selenium-mcp-server/ # TypeScript MCP server (npm: selenium-ai-agent)
│ └── src/
│ ├── server.ts # MCP protocol handler
│ ├── context.ts # Browser session management
│ ├── grid/ # Selenium Grid integration
│ │ ├── grid-client.ts
│ │ ├── session-pool.ts
│ │ └── exploration-coordinator.ts
│ └── tools/ # 73 tools
│ ├── navigation/
│ ├── elements/
│ ├── grid/ # Parallel execution tools
│ ├── agents/ # AI agent tools
│ └── analyzer/ # Risk analysis
│
├── selenium-grid/
│ └── docker-compose.yml # Selenium Grid setup
├── agents/ # Agent prompt definitions
└── docs/ # Guides and diagrams
文档
贡献
欢迎投稿!请阅读我们的投稿指南并提交PR。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
麻省理工学院——见 许可证 了解详情。
致谢
If this project helps you, please give it a star!
Star on GitHub