Token导航 LogoToken导航TokenDH.com
Selenium MCP Server AI Powered Test Generation logo
浏览器工具stdio官方级别未说明来源级核验

Selenium MCP Server AI Powered Test Generation

MCP Server

Selenium MCP Server是一款AI驱动的测试生成工具,通过自然语言描述在VS Code中自动生成完整的Selenium TestNG测试代码,无需手动编写代码或提供元素定位器。

工具数

0

提示词数

0

GitHub Stars

1

资源数

0
自动化测试HTMLClaudeClaudeVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

mvsaran

提供方

mvsaran

最后核验

2026/5/17 20:20

运行时

Node.js

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

npx --version

详细介绍

🚀 Selenium MCP 服务器 - 在 VS Code 中实现 AI 驱动的测试生成(无需编写任何代码!)

在VS Code中使用自然语言生成完整的Selenium TestNG测试——无需编写代码!

📋 目录

______________________________________________________________________

🤖 什么是Selenium MCP?

Selenium MCP(模型上下文协议) 允许VS Code通过AI辅助,从简单的自然语言提示中生成完整、可投入生产的Selenium测试用例。

✨ 主要特点:

  • 🎯(瞄准靶心) 无需编写代码 - 只需描述你想要测试的内容
  • 🔍 翻译为中文是:🔍(这个符号本身在中文中没有直接对应的翻译,但可以理解为表示“放大镜”或“搜索”的意思,常用于表示“查找”、“搜索”或“仔细查看”的动作或状态。) 自动定位检测 - 无需提供定位器!AI会自动找到最佳选择器
  • 🤖 表示机器人。 由人工智能驱动 - AI理解测试的最佳实践和网页元素识别
  • 📝 完整测试 - 生成设置、拆卸、断言和错误处理
  • 🔧 表示“扳手”或“修理工具”的意思,在中文里通常直接用这个符号来表示相关概念,或者根据上下文翻译为“维修工具”、“螺丝刀”等具体工具名称。 准备就绪,随时可运行 - 使用现代框架,如TestNG和WebDriverManager
  • ⚡(闪电符号,常用于表示快速、迅速或能量等概念) 即时 - 几秒钟内获得可运行的测试
  • 💻 表示“电脑”或“笔记本电脑”。 VS Code 集成 - 直接在您的开发环境中工作

______________________________________________________________________

✅ 先决条件

在开始之前,请确保已安装以下内容:

  • 电脑 Visual Studio Code (最新版本)
  • ☕(咖啡) Java开发工具包(JDK) 11或以上
  • 📦 翻译为中文是:“📦”(这个符号本身在中文中通常表示“包裹”或“箱子”,但直接翻译时,由于它是一个图形符号,所以通常保持原样或用其通用含义来解释,即“包裹”或“箱子”的意思)。不过,如果是要表达这个符号所代表的含义,可以简单地说是“包裹”或“箱子”。在这里,为了保持原文的符号形式,直接保留为“📦”。 Maven 3.6或更高版本
  • 🌐 表示“互联网”或“世界万维网”。 Node.js 16岁及以上,且 npm(Node Package Manager) (针对MCP服务器)
  • 🔧 修理工具或螺丝刀的象征 Java 扩展包 (VS Code 扩展)
  • 机器人 配备AI助手的VS Code (GitHub Copilot、Cody 或支持 MCP 的类似工具)

______________________________________________________________________

🛠️ 配置Selenium MCP服务器

步骤1:在VS Code中配置MCP服务器(使用NPX)

配置文件位置:

  1. 导航至您的 VS Code MCP 配置文件:

- Windows: C:\Users\mvsar\AppData\Roaming\Code\User\mcp.json - macOS(发音类似“麦金塔操作系统”,但通常直接称为“macOS”): ~/Library/Application Support/Code/User/mcp.json - Linux~/.config/Code/User/mcp.json

  1. 如果文件不存在,请按以下内容创建它:
{
  "mcpServers": {
    "selenium": {
      "command": "npx",
      "args": [
        "-y",
        "@angiejones/mcp-selenium"
      ]
    }
  }
}
  1. 保存文件

为什么选择NPX?

✅ 无需手动安装\ ✅ 始终使用最新版本\ ✅ 更简洁的配置\ ✅ 无需构建步骤

步骤2:在VS Code中启动MCP服务器

配置服务器后,您需要手动启动它:

  1. 打开命令面板 在 VS Code 中:

- Windows/Linux: Ctrl + Shift + P - macOS:(苹果电脑操作系统) Cmd + Shift + P

  1. 类型MCP: List Servers
  1. 选择: selenium 从列表中
  1. 启动服务器点击开始/播放按钮或选择开始选项
  1. 验证服务器状态服务器状态应显示为“运行中” ✅
⚠️ 重要的确保服务器已开启 在生成测试之前,请检查条件。在VS Code中查看MCP状态指示器。

______________________________________________________________________

📁 项目文件夹结构

设置好你的Maven项目后,你的文件夹结构将如下所示:

selenium-mcp-tests/
│
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/
│   │           └── selenium/
│   │               └── mcp/
│   │                   └── App.java
│   └── test/
│       └── java/
│           └── com/
│               └── selenium/
│                   └── mcp/
│                       ├── RegistrationFormTest.java  🆕 (AI Generated)
│                       └── SampleTest.java            (AI Generated)
│
├── target/                      (Generated after build)
├── pom.xml                      (Maven configuration)
├── package.json                 (Optional)
└── README.md

📝 关键目录解析:

  • src/test/java/com/selenium/mcp/ - 这里是你所有由AI生成的测试文件的存放位置
  • pom.xml - 包含所有Selenium、TestNG和WebDriverManager的依赖项
  • target/ - 包含编译后的类和测试报告(自动生成)
  • 测试文件

- SampleTest.java - SauceDemo 登录和购物车测试 - RegistrationFormTest.java - ParaBank注册表单测试

💡 灯泡(或创意、灵感等意象,具体含义根据上下文而定) 专业提示你无需手动创建这些测试文件!MCP服务器会根据你的自然语言提示自动生成它们。

______________________________________________________________________

📦 在 VS Code 中设置 Maven 项目

步骤1:安装所需的扩展程序

  1. 打开 VS Code
  2. 安装以下扩展:

- ☕ 表示咖啡的符号,可直接译为“咖啡”。在中文语境中,这个符号常用于表示咖啡或与咖啡相关的概念。 Java 扩展包 (由微软提供) - 🔨 表示“锤子”或“敲打”。 Java的Maven (由微软提供) - 🧪 表示“实验瓶”或“实验器材”。 Java 测试运行器 (由微软提供)

步骤2:创建一个新的Maven项目

选项1:使用命令面板

  1. 新闻界(或“媒体”) Ctrl+Shift+P (Windows/Linux) 或 Cmd+Shift+P (macOS)
  2. 输入“Java: 创建Java项目”
  3. 选择 Mavenmaven-archetype-quickstart(Maven快速启动原型)
  4. 按照提示设置您的项目

选项2:使用命令提示符(推荐)

  1. 在VS Code中,打开终端下拉菜单(位于终端区域的右上角)
  2. 选择 “命令提示符” (而不是使用 PowerShell)
  3. 运行这个确切的单行命令:
mvn archetype:generate -DgroupId=com.selenium.mcp -DartifactId=selenium-mcp-tests -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

预期输出:

[INFO] BUILD SUCCESS
[INFO] Created project directory: selenium-mcp-tests
  1. 导航至项目:
cd selenium-mcp-tests
⚠️(注意符号,无直接对应中文含义,可理解为“警告”或“小心”的示意) 使用命令提示符(Command Prompt)而不是 PowerShell,以避免 Maven 命令中的行续接问题。

第三步:配置 pom.xml

在你的项目中添加以下依赖项: pom.xml


    
    
        org.seleniumhq.selenium
        selenium-java
        4.15.0
    
    
    
    
        org.testng
        testng
        7.8.0
        test
    
    
    
    
        io.github.bonigarcia
        webdrivermanager
        5.6.2
    

    

        

            org.apache.maven.plugins
            maven-surefire-plugin
            3.0.0
        

        

            org.apache.maven.plugins
            maven-compiler-plugin
            3.11.0
            
                11
                11
            
        

    

步骤4:更新依赖项

# In VS Code terminal
mvn clean install

______________________________________________________________________

🚦 在 VS Code 中启动 Selenium MCP 服务器

手动启动过程(必需)

配置完成后,需要在VS Code中手动启动MCP服务器:

逐步进行:

  1. 打开 VS Code 命令面板
   Ctrl + Shift + P (Windows/Linux)
   Cmd + Shift + P (macOS)
  1. 搜索并选择

- 类型: MCP: List Servers - 按回车键

  1. 定位Selenium服务器

- 找到 selenium 在已配置服务器列表中

  1. 启动服务器

- 点击 开始 旁边的按钮/图标 selenium - 或者选择启动服务器的选项

  1. 验证状态

- 服务器状态应更改为 “Running” ✅ - 应出现绿色指示灯或对勾标记

🔴(红色圆圈) 关键的;严重的服务器必须处于 在你能够生成测试之前,需要满足条件!

配置文件位置:

Windows: C:\Users\mvsar\AppData\Roaming\Code\User\mcp.json

NPX 配置(已设置):

{
  "mcpServers": {
    "selenium": {
      "command": "npx",
      "args": ["-y", "@angiejones/mcp-selenium"]
    }
  }
}

✅ 验证服务器正在运行

检查 VS Code 的状态栏或 MCP 面板以查看:

  • ✅ 绿色指示灯表示 selenium 服务器
  • ✅ 状态显示为“运行中”或“激活”
  • ✅ 输出面板中无错误信息

______________________________________________________________________

🎯 如何生成测试(无需编写代码!)

这就是魔法发生的地方!一旦你的MCP服务器在VS Code中配置并运行起来,你就可以在不编写任何代码的情况下生成完整的Selenium测试。

步骤1:确保MCP服务器正在运行

  1. 打开命令面板: Ctrl + Shift + P
  2. 类型: MCP: List Servers
  3. 验证 selenium 服务器显示 “Running” 状态 ✅

步骤2:在VS Code中打开你的AI助手

在 VS Code 中使用任何兼容 MCP 的 AI 助手:

  • GitHub Copilot Chat
  • Cody(科迪)
  • 或者任何其他支持MCP的AI扩展

步骤3:使用自然语言提示

只需用简单的英语描述你想测试的内容,AI就会为你生成完整的测试代码!

🔍 无需提供定位器!

这就是魔法所在你甚至不需要告诉AI使用哪些定位器!

❌ 你无需做的事情:

❌ "Use By.id('user-name') to find the username field"
❌ "Locate the button with XPath //button[@id='login']"
❌ "Find element by CSS selector input.form-control"

✅ 你实际说的是:

✅ "Fill in the username field with 'standard_user'"
✅ "Click the login button"
✅ "Enter password in the password field"

MCP服务器自动地

  • 🔍 检查网页结构
  • 🎯 确定最佳定位器(ID、名称、CSS、XPath)
  • ✨ 生成最优元素定位策略
  • 🛡️ 添加了适当的等待和错误处理
  • ✅ 生成可直接投入生产的代码

🧪 示例提示(来自我们的项目):

🧪 Generate a Selenium TestNG test that visits https://www.saucedemo.com/
, logs in with standard_user and secret_sauce, verifies the PRODUCTS 
heading, and adds the Sauce Labs Backpack to the cart.

通知未提及定位器!AI自行推断:

  • By.id("user-name") 用于用户名字段
  • By.id("password") 用于密码字段
  • By.id("login-button") 用于登录按钮
  • By.xpath("//span[@class='title']") 对于“产品”标题
  • By.id("add-to-cart-sauce-labs-backpack") 用于购物车按钮

步骤4:AI生成完整测试

AI助手将自动创建一个 完整的、可投入生产的测试 包括:

包声明 以及所有必要的导入\ ✅ WebDriver 设置 使用WebDriverManager\ ✅ @BeforeMethod - 初始化浏览器并导航到URL\ ✅ @Test 方法 具有适当的测试逻辑:

  • 使用凭据登录
  • 等待元素加载
  • 验证“PRODUCTS”(产品)标题
  • 找到并点击“加入购物车”以购买Sauce Labs背包
  • 验证购物车徽章更新

✅(勾选标记,表示正确、确认或完成) \@AfterMethod\ 翻译成中文是“方法执行后” - 正确清理并关闭浏览器\ ✅ 显式等待 - 使用ExpectedConditions的WebDriverWait\ ✅ 断言 - 使用TestNG断言来验证预期行为\ ✅ 错误处理 - 在需要的地方使用try-catch块

📄 你将获得的内容(无需编写任何代码!):

package com.selenium.mcp;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.time.Duration;

public class SampleTest {
    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeMethod
    public void setup() {
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(10));
        driver.manage().window().maximize();
    }

    @Test
    public void sauceDemoLoginAndAddToCart() {
        // Navigate to Sauce Demo
        driver.get("https://www.saucedemo.com/");
        
        // Login
        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("user-name")))
            .sendKeys("standard_user");
        driver.findElement(By.id("password")).sendKeys("secret_sauce");
        driver.findElement(By.id("login-button")).click();
        
        // Verify PRODUCTS heading
        WebElement productsHeading = wait.until(
            ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//span[@class='title']")
            )
        );
        Assert.assertEquals(productsHeading.getText(), "PRODUCTS");
        
        // Add Sauce Labs Backpack to cart
        driver.findElement(By.id("add-to-cart-sauce-labs-backpack")).click();
        
        // Verify cart badge
        WebElement cartBadge = driver.findElement(By.className("shopping_cart_badge"));
        Assert.assertEquals(cartBadge.getText(), "1");
    }

    @AfterMethod
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }
}

🎉 就是它了!

你没有写一行代码 - 通过MCP服务器,AI根据您的自然语言提示生成了所有内容!

步骤5:保存并运行

  1. 保存生成的代码 到你的测试目录:

- src/test/java/com/selenium/mcp/SampleTest.java

  1. 运行测试
   mvn test
  1. 观察它的执行过程 自动地!

______________________________________________________________________

💡 更多提示示例

你可以使用自然语言生成任何类型的Selenium测试:

示例1:表单测试

Generate a test that fills out a contact form with name, email, and message, 
then verifies the success message appears

示例2:导航测试

Create a test that navigates through a multi-page checkout flow, verifies 
each page title, and completes the purchase

示例3:数据驱动测试

Generate a test that logs in with multiple user credentials and verifies 
different dashboard elements for each user type

示例4:API + UI测试

Create a test that makes an API call to create a user, then verifies 
the user appears in the UI dashboard

示例5:注册表单自动化 🆕

Create a Selenium Java script that automates the process of filling out 
the registration form on the page at "https://parabank.parasoft.com/parabank/register.htm" 
with fake data. The script should:
1. Navigate to the registration URL
2. Fill out the form with the following fake data:
   - First Name: John
   - Last Name: Doe
   - Address: 123 Fake Street
   - City: Faketown
   - State: FT
   - Zip Code: 12345
   - Phone Number: 5551234567
   - SSN: 123-45-6789
   - Username: johndoe123
   - Password: password123
   - Confirm Password: password123
3. Submit the registration form
4. Wait for the registration to complete using explicit waits
5. Verify the successful registration or page redirection
6. Close the browser after the test

Make sure the script uses ChromeDriver with WebDriverManager and waits 
appropriately for elements to load.

______________________________________________________________________

🎯 为何这如此强大

传统方法使用Selenium MCP
✍️ 手动编写所有代码💬 用自然语言描述
🔍 检查元素并查找定位器🤖 AI自动寻找最佳定位器
⏱️ 创建测试所需小时数⚡ 生成所需秒数
🐛 调试语法错误✅ 准生产就绪代码
记住API语法🤖 AI最了解最佳实践
🔄 反复重构🎯 一次做对
🧪 手动元素识别🔍 自动元素检测

______________________________________________________________________

🧪 示例用法

🧪 真实世界的成功案例

我们的项目示例:

我们的所作所为:

  1. ✅ 配置MCP服务器(5分钟)
  2. ✅ 创建了Maven项目(2分钟)
  3. ✅ 给Claude一个简单的提示
  4. ✅ 已获得一个完整且能正常运行的测试 无需编写任何代码!

提示:

🧪 Generate a Selenium TestNG test that visits https://www.saucedemo.com/
, logs in with standard_user and secret_sauce, verifies the PRODUCTS 
heading, and adds the Sauce Labs Backpack to the cart.

结果:

  • ✅ 完整的测试类,包含50多行专业代码
  • ✅ 所有导入和依赖项均已处理
  • ✅ WebDriverManager 集成
  • ✅ 显式等待和适当的同步
  • ✅ TestNG 注解和断言
  • ✅ 清晰的设置和清理过程
  • 首次尝试即成功运行!

节省的时间: 30-45分钟的手工编码 → 30秒的AI编码

______________________________________________________________________

🆕 注册表单自动化示例

你可以使用的提示语:

Create a Selenium Java script that automates the process of filling out 
the registration form on the page at "https://parabank.parasoft.com/parabank/register.htm" 
with fake data. The script should:
1. Navigate to the registration URL
2. Fill out the form with the following fake data:
   - First Name: John
   - Last Name: Doe
   - Address: 123 Fake Street
   - City: Faketown
   - State: FT
   - Zip Code: 12345
   - Phone Number: 5551234567
   - SSN: 123-45-6789
   - Username: johndoe123
   - Password: password123
   - Confirm Password: password123
3. Submit the registration form
4. Wait for the registration to complete using explicit waits
5. Verify the successful registration or page redirection
6. Close the browser after the test

Make sure the script uses ChromeDriver with WebDriverManager and waits 
appropriately for elements to load.
🔍(放大镜图标,通常表示搜索或查看细节) 通知你没有指定任何定位器(比如 By.nameBy.idBy.xpath)! MCP服务器自动检查ParaBank页面并发现: - By.name("customer.firstName") 用于名字(或:作为名字) - By.name("customer.lastName") 用于姓氏 - By.name("customer.address.street") 对于地址 - By.name("customer.username") 用于用户名 - By.cssSelector("input[value='Register']") 用于“提交”按钮 - 以及所有其他最优定位器!

你将获得(由AI生成):

package com.selenium.mcp;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.time.Duration;

public class ParaBankRegistrationTest {
    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeMethod
    public void setup() {
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(15));
        driver.manage().window().maximize();
    }

    @Test
    public void testRegistrationForm() {
        // Navigate to registration page
        driver.get("https://parabank.parasoft.com/parabank/register.htm");
        
        // Wait for the form to load
        wait.until(ExpectedConditions.presenceOfElementLocated(
            By.name("customer.firstName")
        ));
        
        // Fill out the registration form
        driver.findElement(By.name("customer.firstName")).sendKeys("John");
        driver.findElement(By.name("customer.lastName")).sendKeys("Doe");
        driver.findElement(By.name("customer.address.street")).sendKeys("123 Fake Street");
        driver.findElement(By.name("customer.address.city")).sendKeys("Faketown");
        driver.findElement(By.name("customer.address.state")).sendKeys("FT");
        driver.findElement(By.name("customer.address.zipCode")).sendKeys("12345");
        driver.findElement(By.name("customer.phoneNumber")).sendKeys("5551234567");
        driver.findElement(By.name("customer.ssn")).sendKeys("123-45-6789");
        
        // Username and password fields
        driver.findElement(By.name("customer.username")).sendKeys("johndoe123");
        driver.findElement(By.name("customer.password")).sendKeys("password123");
        driver.findElement(By.name("repeatedPassword")).sendKeys("password123");
        
        // Submit the form
        driver.findElement(By.cssSelector("input[value='Register']")).click();
        
        // Wait for registration success message or page redirect
        WebElement successMessage = wait.until(
            ExpectedConditions.presenceOfElementLocated(
                By.cssSelector("div.title, p")
            )
        );
        
        // Verify successful registration
        String pageText = driver.getPageSource();
        Assert.assertTrue(
            pageText.contains("Your account was created successfully") || 
            pageText.contains("Welcome"),
            "Registration was not successful"
        );
        
        System.out.println("✅ Registration completed successfully!");
    }

    @AfterMethod
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }
}

🎉 这个测试的作用:

导航 跳转到ParaBank注册页面\ ✅ 表示“正确”或“对”的意思。 等待 以便表单元素能够正确加载\ ✅ 表示“正确”或“已确认”。 填写完整 所有11个表单字段均包含测试数据\ ✅ 提交 注册表格\ ✅ 验证 成功注册并附带断言\ ✅ 清理干净 通过关闭浏览器\ ✅ 采用最佳实践WebDriverManager,显式等待,适当的断言

💡 主要特点:

  • 显式等待用途 WebDriverWait 带有15秒超时设置
  • 智能元素定位AI自动选择了最佳定位器:

- By.name() 对于表单字段(对表单而言最可靠) - By.cssSelector() 用于提交按钮 - 无需手动定位器研究!

  • 验证检查是否有成功消息或欢迎文本
  • 错误处理适当的清理工作 @AfterMethod
  • WebDriverManager自动驱动程序管理
  • TestNG 集成完整的TestNG注解和断言

🔍 MCP如何找到定位器:

人工智能分析了ParaBank的注册页面,并自动发现了:

字段AI选定的定位符为何选择此定位符?
By.name("customer.firstName")表单输入最稳定
姓氏By.name("customer.lastName") 语义明确且可靠
地址By.name("customer.address.street")分层名称结构
城市 By.name("customer.address.city")清晰的字段标识
用户名 By.name("customer.username")标准形式命名
密码By.name("customer.password")安全字段定位器
提交按钮By.cssSelector("input[value='Register']")按钮唯一标识符

你本不必:

  • 打开开发者工具以检查元素 ❌
  • 编写XPath表达式 ❌
  • 测试不同的定位器 ❌
  • 担心定位器的稳定性 ❌

MCP 为您包办一切! ✅ 表示“正确”或“完成”。

📊 运行测试:

将文件另存为 ParaBankRegistrationTest.java 在:

src/test/java/com/selenium/mcp/ParaBankRegistrationTest.java

使用 Maven 运行:

mvn test -Dtest=ParaBankRegistrationTest

在VS Code中右键点击并选择 运行测试

______________________________________________________________________

📊 测试执行结果

# Using Maven
mvn test

# Run specific test class
mvn test -Dtest=SampleTest

# Run ParaBank registration test
mvn test -Dtest=ParaBankRegistrationTest

# Using TestNG directly in VS Code
# Right-click on the test file → Run Test

______________________________________________________________________

🔧 故障排除

常见问题:

❌ MCP 服务器无法启动

解决方案:

# Verify Node.js is installed
node --version  # Should be 16.x or higher

# Verify NPX is available
npx --version

# Test the MCP server manually
npx -y @angiejones/mcp-selenium

检查配置文件:

  • Windows:验证 C:\Users\mvsar\AppData\Roaming\Code\User\mcp.json 存在
  • 确保JSON语法正确(无尾随逗号)
  • 完全重启 VS Code

手动启动服务器:

  1. 打开命令面板: Ctrl + Shift + P
  2. 类型: MCP: List Servers
  3. 选择 selenium 并点击开始
  4. 验证状态显示为“运行中”

❌ Maven 依赖项未解析

解决方案:

# Force update dependencies
mvn clean install -U

# Clear Maven cache
rm -rf ~/.m2/repository
mvn clean install

❌ WebDriver 问题

解决方案:

// Use WebDriverManager in your test setup
import io.github.bonigarcia.wdm.WebDriverManager;

@BeforeMethod
public void setup() {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
}

❌ VS Code 无法检测到 MCP 服务器

解决方案:

  1. 验证配置文件路径:

- Windows: C:\Users\mvsar\AppData\Roaming\Code\User\mcp.json

  1. 确保NPX命令正确无误:
   {
     "mcpServers": {
       "selenium": {
         "command": "npx",
         "args": ["-y", "@angiejones/mcp-selenium"]
       }
     }
   }
  1. 完全重启 VS Code
  2. 手动启动服务器:

- 命令面板 → MCP: List Servers → 选择 selenium → 开始

  1. 检查 VS Code 的输出面板以查看错误信息

❌ 在ParaBank测试中未找到元素

解决方案:

// Increase wait time if elements load slowly
wait = new WebDriverWait(driver, Duration.ofSeconds(20));

// Add implicit wait as backup
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

// Use more flexible locators
wait.until(ExpectedConditions.or(
    ExpectedConditions.presenceOfElementLocated(By.name("customer.firstName")),
    ExpectedConditions.presenceOfElementLocated(By.id("customer.firstName"))
));

______________________________________________________________________

📚 资源

______________________________________________________________________

👨‍💻 作者

萨兰·库马尔

______________________________________________________________________

📝 许可证

这个项目遵循以下许可条款: MCP-Selenium 仓库。

______________________________________________________________________

🎯 快速启动检查清单

  • \[ \] 安装先决条件(JDK 11+,Maven 3.6+,Node.js 16+)
  • \[ \] 安装带有Java扩展包的VS Code
  • \[ \] 配置 mcp.json 使用NPX命令(C:\Users\mvsar\AppData\Roaming\Code\User\mcp.json)
  • \[ \] 使用命令提示符在 VS Code 中创建 Maven 项目
  • \[ \] 在pom.xml中添加Selenium依赖(运行 mvn clean install)
  • \[ \] 🚦 启动MCP服务器:命令面板 → MCP: List Servers → 选择 selenium → 开始
  • \[ \] ✅ 验证服务器状态显示为“运行中”
  • \[ \] 在VS Code中开启Open AI助手(Copilot/Cody)
  • \[ \] 🎯 给AI一个描述你测试的提示
  • \[ \] ✨ 观看AI生成完整的测试代码(无需编程!)
  • \[ \] 将生成的代码保存到您的测试目录中
  • \[ \] 运行 mvn test 并看到它发挥作用!

______________________________________________________________________

🌟 重点总结

在VS Code中,您无需编写任何一行代码即可创建全面且可投入生产的Selenium测试! 仅仅;只是

  1. 配置并启动MCP服务器
  2. 用简单的英语向你的AI助手描述你想测试的内容
  3. 获取包含最佳实践、适当的等待机制、断言以及错误处理的完整且可运行的代码

🔍 无需定位器!

最大的优势你永远不需要提供元素定位器!MCP服务器:

  • 🌐 自动分析目标网页
  • 🎯 确定最可靠的定位器(ID、名称、CSS、XPath)
  • ✨ 为每个元素选择最佳的布局策略
  • 🛡️ 添加适当的等待和错误处理
  • ✅ 生成生产级代码

📋 包含两个完整示例:

  1. SauceDemo 登录与购物车测试 - 电子商务工作流程测试

- 自动检测到:用户名字段、密码字段、登录按钮、购物车按钮

  1. ParaBank注册测试 🆕 - 带验证的表单自动化

- 自动检测到:11个字段,已优化 By.name() 定位器(或定位元素) - 自动检测到:带有(提交)按钮 By.cssSelector()

这两个示例展示了AI生成的Selenium测试在无需任何手动编码的情况下所展现出的强大功能 且未进行手动定位器研究

______________________________________________________________________

测试顺利! 🎉(庆祝、欢呼)

目录标签

目录标签

自动化测试HTMLClaude本地部署AI测试生成无代码测试SeleniumTestNG

支持客户端

ClaudeVS Code

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

session

运行时(runtime,运行环境)

Node.js

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiosession部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP