DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Modern Test Automation With AI (LLM) and Playwright MCP
  • Testing AI Is the First Step to Using AI
  • Exploring Playwright’s Feature “Copy Prompt”
  • Build AI Agents With MCP Server in C# and Run in VS Code

Trending

  • Maximizing Return on Investment When Securing Our Supply Chains: Where to Focus Our Limited Time to Maximize Reward
  • Master AI Development: The Ultimate Guide to LangChain, LangGraph, LangFlow, and LangSmith
  • *You* Can Shape Trend Reports: Join DZone's Data Engineering Research
  • Lessons Learned in Test-Driven Development
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Integrating Cursor and LLM for BDD Testing With Playwright MCP (Model Context Protocol)

Integrating Cursor and LLM for BDD Testing With Playwright MCP (Model Context Protocol)

Learn in this article how BDD, AI-powered Cursor, and Playwright MCP simplify test automation, enabling faster, smarter, and more collaborative workflows.

By 
Kailash Pathak user avatar
Kailash Pathak
DZone Core CORE ·
Jun. 11, 25 · Tutorial
Likes (0)
Comment
Save
Tweet
Share
1.2K Views

Join the DZone community and get the full member experience.

Join For Free

Imagine writing automated tests that feel like describing a story, where your natural language ideas transform into robust, executable code in seconds.

It’s reality, thanks to the convergence of AI-powered tools like Cursor, Large Language Models (LLMs), and the Playwright Model Context Protocol (MCP). These tools are enhancing Behavior Driven Development (BDD), making test automation faster, smarter, and more collaborative.

In this blog, I’ll share a practical example of automating a login test, along with real-world insights.

By the end of the blog, you’ll see how, without doing any setup for Playwright and BDD/Cucumber, we can execute the feature file.

Why This Matters

Test automation has come a long way from brittle, hand-coded scripts. Today, it’s about bridging the gap between human intent and machine execution. BDD ensures tests are written in plain English, fostering collaboration across teams. Cursor, an AI-powered IDE, uses LLMs to generate code from natural language prompts. 

Playwright MCP, a protocol from Anthropic, enables LLMs to interact with browsers through accessibility trees, making tests resilient to UI changes. Together, they create a powerful trio that reduces manual effort, improves test coverage, and makes testing fun.

Understanding the Key Components

Before we jump into the code, let’s break down the tools we’re working with:

  • Behavior-Driven Development (BDD): A methodology where tests are written in Gherkin syntax (Given-When-Then) to describe application behavior in plain English. Tools like Cucumber or playwright-bdd translate these scenarios into executable tests.
  • Cursor: An AI-powered IDE that integrates LLMs (e.g., Claude 3.5, GPT-4o, etc.) to generate code, suggest fixes, and streamline development. Think of it as VS Code with a super-smart assistant.
  • Large language models (LLMs): AI models that understand and generate human-like text and code. They power Cursor’s ability to translate natural language into test scripts.
  • Playwright MCP: A protocol that enables LLMs to control Playwright, a browser automation tool, using structured accessibility trees instead of fragile screenshot-based methods. This ensures robust, reliable tests.

Setting Up Your Environment

Install Node.js

Playwright and MCP require Node.js. Download the latest version from nodejs.org or install via a package manager.

Install Cursor

Download Cursor from cursor.com and install it. Configure it with your preferred LLM (e.g., Claude 3.5 or GPT-4o) via the settings panel. You’ll need an API key from your LLM provider.

Configure Playwright MCP

Playwright MCP is the bridge between LLMs and Playwright.

Install the MCP Server

Shell
 
npm install @executeautomation/playwright-mcp-server


Create a configuration file (.cursor/mcp.json) in your project root:

JSON
 
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}
Create a configuration file


Writing a BDD Test With Cursor and Playwright MCP

To demonstrate, we’ll automate a login test for the Lambdatest playground site.

Our goal is to write a Gherkin scenario, use Cursor /and LLM to generate step definitions, and let Playwright MCP handle browser interactions.

Step 1

Write a Gherkin Feature file named login.feature in the root folder.

Plain Text
 
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 "[email protected]"
    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

Write a Gherkin Feature file


Step 2

Open the cursor settings and make sure all tools are loaded properly.

Ensure all tools are loaded properly


Step 3

Open the cursor chat window.

Plain Text
 
Make Sure Agent is selected.
LLM model is selected , We can keep it "Auto" or Select as per our choice.
Cursor chat window
Make sure "Auto" is turned on


Step 4

Write the instruction in the Cursor chat window, e.g, “Read the feature file and execute the steps mentioned.” A video is attached below.


In the above video, you can see, without doing any setup for BDD /Cucumber and Playwright, how we can execute the feature file.

Benefits and Challenges

Benefits

  • Speed: Cursor generates step definitions in seconds, saving hours of manual coding.
  • Resilience: MCP’s accessibility tree approach minimizes test failures due to UI updates.
  • Collaboration: Gherkin scenarios are readable by product managers, developers, and testers, fostering teamwork.
  • Scalability: Integrate with CI/CD tools, such as GitHub Actions, for automated testing.

Challenges

  • Complex scenarios: MCP excels at simple UI tests but may struggle with multi-step workflows requiring custom logic.
  • Setup overhead: Configuring MCP servers and Cursor’s LLM integration takes time.
  • Security: If using cloud-based LLMs, ensure sensitive test data (e.g., credentials) is masked or stored securely.

Best Practices for Secure and Private Use of LLMs in Test Automation

Mask Sensitive Data in Test Scripts

  • Never hardcode credentials or tokens.
  • Use environment variables or secrets managers to store and retrieve sensitive data dynamically.

Use On-Premise or Private LLMs

  • Prefer on-premises or self-hosted LLMs where possible to prevent external transmission of sensitive test data.
  • If using a cloud-based LLM, verify if it supports data isolation, non-persistence, and opt-out from training.

Understand and Review Data Privacy Policies

  • Carefully review your LLM provider’s data usage and retention policies.

Regular Security Audits and Compliance Checks

  • Conduct periodic security audits of your test environment and infrastructure.
  • Validate compliance with regulatory frameworks like GDPR, CCPA, or industry-specific guidelines.

Limit LLM Exposure

  • Avoid feeding the LLM with full test suites or sensitive scenario details unless necessary.
  • Use prompt engineering techniques to limit the exposure of proprietary or confidential data during interactions.

Conclusion

Integrating Cursor, LLMs, and Playwright MCP for BDD testing is a game-changer. It combines the clarity of Gherkin, the intelligence of AI, and the reliability of accessibility-driven automation.

Protocol (object-oriented programming) Testing large language model

Opinions expressed by DZone contributors are their own.

Related

  • Modern Test Automation With AI (LLM) and Playwright MCP
  • Testing AI Is the First Step to Using AI
  • Exploring Playwright’s Feature “Copy Prompt”
  • Build AI Agents With MCP Server in C# and Run in VS Code

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: