设置环境

安装 Node.js :Playwright 和 MCP 需要 Node.js

安装 Cursor :从Cursor官网下载并安装Cursor,在设置面板,选择首选的LLM

配置 Playwright MCP: Playwright MCP 是 LLM 和 Playwright 之间的桥梁

安装MCP服务器
mkdir playwright-mcp-bdd
cd playwright-mcp-bdd
npm install @executeautomation/playwright-mcp-server
打开项目

使用Cursor打开playwright-mcp-bdd

在项目根目录中创建一个配置文件(.cursor/mcp.json)

mkdir -p .cursor && touch .cursor/mcp.json
{
    "mcpServers": {
      "playwright": {
        "command": "npx",
        "args": ["-y", "@executeautomation/playwright-mcp-server"]
      }
    }
  }  

编写BDD测试

使用 Cursor 和 Playwright MCP 编写 BDD 测试

Step1:新建feature文件
Feature: Login to LambdaTest E-Commerce Playground

  Scenario: Successful login with valid credentials
    Given I open the login page https://ecommerce-playground.lambdatest.io/index.php?route=account/login
    When I enter E-Mail Address "timcook@yopmail.com"
    And I enter Password "Test@1234"
    And I click on the Login button
    Then I should see "My Account" text on the logged in page
    When I click on "Edit your account information" link
    Then I should see "My Account Information" text on the page
    When I clear the "First Name" field
    And I enter "Kailash" in the "First Name" field
    And I clear the "Last Name" field
    And I enter "Pathak" in the "Last Name" field
    And I click on the Continue button
    Then I should see "Success: Your account has been successfully updated." text on the page
    Then Close the browser
Step2:检查Cursor设置

确保MCP开关已打开
在这里插入图片描述

Step3:在Cursor聊天窗口输入指令

在这里插入图片描述

执行视频

test

从上面的视频中,我们可以看到无需对 BDD 和 Playwright 进行任何设置,就可以执行功能文件。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐