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.
Join the DZone community and get the full member experience.
Join For FreeImagine 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
npm install @executeautomation/playwright-mcp-server
Create a configuration file (.cursor/mcp.json) in your project root:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "@executeautomation/playwright-mcp-server"]
}
}
}

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.
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
Step 2
Open the cursor settings and make sure all tools are loaded properly.

Step 3
Open the cursor chat window.
Make Sure Agent is selected.
LLM model is selected , We can keep it "Auto" or Select as per our choice.


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.
Opinions expressed by DZone contributors are their own.
Comments