The MCP Cypress Page Object & Test Generator is a powerful tool that automatically creates TypeScript Page Object classes and Cypress test suites for web pages. It uses web scraping and HTML parsing to analyze page elements and generate comprehensive, ready-to-use test code.
To install the MCP Cypress Page Object & Test Generator, run:
npm install
Launch the server with the following command:
npx tsx main.ts
The server provides a generateLocator tool that accepts a URL parameter. Here's how to call it:
{
"method": "tools/call",
"params": {
"name": "generateLocator",
"arguments": {
"url": "https://example.com/login"
}
}
}
The response contains two generated files:
{ClassName}.ts){ClassName}.cy.ts)export class ExampleComLoginPage {
// Private elements
#elements = {
button_login: () => cy.get('#login-button'),
input_username: () => cy.get('input[name="username"]'),
link_home: () => cy.contains('a', 'Home')
}
// Public getters
get ButtonLogin() { return this.#elements.button_login() }
get InputUsername() { return this.#elements.input_username() }
get LinkHome() { return this.#elements.link_home() }
// Interaction methods
clickButtonLogin() { return this.#elements.button_login().click() }
typeInputUsername(text: string) { return this.#elements.input_username().type(text) }
clickLinkHome() { return this.#elements.link_home().click() }
// Workflow methods
login(username: string, password: string) {
this.typeInputUsername(username)
this.typeInputPassword(password)
this.clickButtonLogin()
return this
}
}
import { ExampleComLoginPage } from './ExampleComLoginPage'
describe('ExampleComLoginPage Tests', () => {
let page: ExampleComLoginPage
beforeEach(() => {
cy.visit('https://example.com/login')
page = new ExampleComLoginPage()
})
describe('Element Interactions', () => {
it('should click button_login', () => {
page.clickButtonLogin()
})
it('should type in input_username', () => {
page.typeInputUsername('test input')
page.getInputUsername().should('have.value', 'test input')
})
})
describe('Login Workflow', () => {
it('should login with valid credentials', () => {
page.login('[email protected]', 'validpassword')
cy.url().should('not.include', '/login')
})
it('should show error with invalid credentials', () => {
page.login('[email protected]', 'wrongpassword')
cy.contains('Invalid credentials').should('be.visible')
})
})
describe('Error Handling', () => {
it('should handle network errors gracefully', () => {
cy.intercept('GET', '**', { forceNetworkError: true })
cy.visit('https://example.com/login')
})
})
})
To use the generated Page Object in your own tests:
// Import the generated Page Object
import { ExampleComLoginPage } from './ExampleComLoginPage'
describe('Login Page', () => {
const page = new ExampleComLoginPage()
it('should login successfully', () => {
page.login('username', 'password')
page.verifyPageLoaded()
})
})
To run the generated test suite:
npx cypress run --spec "cypress/e2e/ExampleComLoginPage.cy.ts"
The generator creates multiple types of tests:
The generator handles various HTML elements:
The tool intelligently identifies common patterns:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "cypress-test-generator" '{"command":"npx","args":["tsx","main.ts"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:
{
"mcpServers": {
"cypress-test-generator": {
"command": "npx",
"args": [
"tsx",
"main.ts"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"cypress-test-generator": {
"command": "npx",
"args": [
"tsx",
"main.ts"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect