Skip to content
Projects

padmarajnidagundi/Playwright-AI-Agent-POM-MCP-Server

View on GitHub

About

Playwright AI Agent POM MCP ServerPlaywright AI Agent using Page Object Model (POM) architecture with MCP Server integration for automated web and mobile testing

AI & Machine Learning

How these counts are measured

What you can do

  • Skills: reusable instruction files or modular capabilities that teach an AI how to perform a specific, repeatable task on demand.
  • Tool use (function calling): the ability of an AI model to interact with external software, such as searching the web, querying a database, or sending an email, instead of only generating text.
  • MCP (Model Context Protocol): an open standard that acts like a USB-C port for AI, allowing models to connect to external applications and data sources, such as Google Drive, Notion, or Jira, without custom code for each integration.
  • RAG (Retrieval-Augmented Generation): a technique that retrieves relevant facts from private documents or a database before answering, keeping responses grounded in real data.

Measured star growth

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

Playwright AI Agent POM MCP Framework

A practical Playwright, Page Object Model (POM), and AI-agent testing framework for web, API, accessibility, security, resilience, and mobile checks.

CI Playwright TypeScript License

QA adoption guide

Use this guide to adopt the framework for an application or team. The repository is ready for QA automation once the setup steps below are complete; no additional test runner or reporting package is required.

1. Choose the target and environments

Start with a non-production environment. Set E2E_BASE_URL to the application URL that Playwright should test:

export E2E_BASE_URL="https://qa.example.com"
npm run test:smoke

On Windows PowerShell:

$env:E2E_BASE_URL="https://qa.example.com"
npm run test:smoke

Store tokens and other secrets in CI secrets or environment variables. Do not place credentials in specs, Page Objects, or tests/data/.

2. Install and run a baseline

Prerequisite: Node.js 20+.

npm ci
npx playwright install --with-deps
npm run test:smoke
npm run test:chromium
npm run test:report

The first smoke run confirms that dependencies, browsers, network access, and the target environment work together. Use headed mode during local investigation:

npm run test:headed

For a single journey:

npx playwright test tests/indiaRealtime.spec.ts --project=chromium --headed
npx playwright test tests/security-tests/ --project=chromium

3. Map the application into the framework

Add centralized application data under tests/data/:

  • Environment URLs and route paths
  • Shared test users and test account identifiers
  • Stable application constants and thresholds
  • API endpoints used by integration and contract tests

Create a Page Object under tests/pages/ for each high-value user-facing page or component. Put selectors and UI actions in the Page Object, while specs should describe the scenario and assert the expected business behavior.

Recommended workflow for the first new journey:

  1. Identify the critical path and expected result.
  2. Add URL or test data to tests/data/.
  3. Add a small Page Object with stable role/label/data-testid locators.
  4. Add or update a spec under the matching category in tests/.
  5. Run only that spec while it is being developed.
  6. Run the relevant category and npm run typecheck.
  7. Open a pull request and let CI run the blocking suites.

Example spec and POM structure:

// tests/pages/LoginPage.ts
import { Page, expect } from '@playwright/test';
import { BasePage } from './BasePage';

export class LoginPage extends BasePage {
  readonly url = '/login';

  constructor(page: Page) {
    super(page);
  }

  async open() {
    await this.goto(this.url);
  }

  async expectReady() {
    await expect(this.page.getByRole('heading', { name: 'Login' })).toBeVisible();
  }
}
// tests/e2e/login.spec.ts
import { test } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';

test('login page is available', async ({ page }) => {
  const login = new LoginPage(page);
  await login.open();
  await login.expectReady();
});

Place specs in the category that matches their purpose:

QA need Directory
Browser critical journeys tests/e2e/ or tests/indiaRealtime.spec.ts
Accessibility tests/accessibility/
API contracts tests/contract-tests/
Authentication and injection tests/security-tests/
Mobile behavior tests/mobile.spec.ts
Integration workflows tests/integration-tests/
Network failures and resilience tests/network-resilience/ or tests/resilience/
Validation and invalid routes tests/validation-tests/

4. Establish CI as the quality gate

On pushes and pull requests targeting main or develop, CI performs formatting, unit, integration, and smoke checks. The CI workflow also audits dependencies and scans changed commits for secrets. Treat these blocking checks as merge criteria:

npm run format:check
npm run typecheck
npm run test:unit
npm run test:integration
npm run test:smoke

CI uploads Playwright HTML reports, JSON/JUnit results, screenshots, traces, and videos when available. Add E2E_BASE_URL, E2E_API_TOKEN, and any other required test configuration to the CI environment or repository secrets.

5. Triage failures consistently

For a failing run:

  1. Run the smallest failing spec locally with --headed or --debug.
  2. Inspect test-results/ai-report.json for the normalized status and root-cause hints.
  3. Open test-results/error-context.md, the Playwright trace, or HTML report.
  4. Fix the root behavior or selector in the relevant Page Object.
  5. Rerun the failing spec, then the category, before submitting the change.

Do not put fixed sleeps in tests. Prefer Playwright locators and assertions, response waiting, and Page Object wait helpers. If a locator change is proposed by an AI tool, review the POM diff and rerun the affected tests before applying it.

Quick start

Requirements: Node.js 20+.

npm ci
npx playwright install --with-deps
npm run test:smoke

Use Chromium for the fastest local feedback:

npm run test:chromium
npm run test:headed
npm run test:report

Set a target application with an environment variable:

E2E_BASE_URL=https://your-app.example npm run test:smoke
E2E_API_TOKEN=your-token npm run test:chromium

PowerShell:

$env:E2E_BASE_URL="https://your-app.example"
npm run test:smoke

Common commands

Command Purpose
npm test Run the complete configured suite
npm run test:unit Run platform and utility unit tests
npm run test:integration Run integration tests
npm run test:smoke Run the smoke suite in Chromium
npm run test:a11y Run accessibility and keyboard checks
npm run test:security Run security-focused Playwright specs
npm run test:mobile Run mobile-project coverage
npm run test:chromium Run the full suite in Chromium
npm run test:headed Run in headed mode
npm run test:report Open the HTML report
npm run typecheck Check TypeScript types
npm run format:check Check formatting
npm run mcp:server Start the JSON-RPC/MCP server

To run one spec or category:

npx playwright test tests/indiaRealtime.spec.ts --project=chromium
npx playwright test tests/security-tests/ --project=chromium
npx playwright test tests/indiaRealtime.spec.ts --project=chromium --headed

Architecture

AI agent / MCP client
        |
        v
mcp-server.ts  ── test selection, failure analysis, reporting, guarded healing
        |
        v
Playwright runner
        |
        +-- tests/*.spec.ts
        +-- tests/pages/*Page.ts
        +-- tests/data/*.ts
        +-- tools/ai-reporter.ts
        +-- tools/platform/*
  • Specs orchestrate scenarios and assertions.
  • Page Objects own selectors and UI actions. Keep selectors out of spec files.
  • Test data belongs in tests/data/; configure URLs and tokens through environment variables.
  • Fixtures provide API contexts and failure tracing.
  • Reporter creates an AI-readable failure report.
  • MCP server lets compatible agents run tests and inspect results without bypassing framework guardrails.

Repository layout

tests/
  data/                   Centralized URLs, users, thresholds
  pages/                  Page Objects and shared BasePage
  fixtures.ts             Shared Playwright fixtures
  indiaRealtime.spec.ts        Main smoke coverage
  unit-tests/             Fast platform tests
  integration-tests/      Multi-step workflows
  accessibility/          Axe and keyboard checks
  security-tests/         Authentication and XSS checks
  validation-tests/       Broken links and invalid inputs/routes
  network-resilience/     Offline/network scenarios
  contract-tests/         API contract checks
  ...
tools/
  ai-reporter.ts          Structured run output
  platform/               Failure analysis, trace summaries, healing,
                          test selection, metrics, and redaction
mcp-server.ts             MCP/JSON-RPC entrypoint
playwright.config.ts      Browser projects and reporters

Writing tests

Create a Page Object for UI selectors and actions:

import { Page, expect } from '@playwright/test';
import { BasePage } from './BasePage';

export class LoginPage extends BasePage {
  readonly url = '/login';

  constructor(page: Page) {
    super(page);
  }

  async open() {
    await this.goto(this.url);
  }

  async submit(username: string) {
    await this.safeFill(this.page.getByLabel('Username'), username, 'username');
  }

  async expectReady() {
    await expect(this.page.getByRole('heading', { name: 'Login' })).toBeVisible();
  }
}

Keep the spec focused on behavior:

import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';

test('shows login form', async ({ page }) => {
  const login = new LoginPage(page);
  await login.open();
  await login.expectReady();
});

Prefer role, label, and data-testid locators. Use Playwright waits and assertions instead of fixed sleeps.

AI-agent workflow

After a run, AI tools can consume:

  • test-results/ai-report.json — normalized test status and root-cause hints
  • test-results/results.json — standard Playwright JSON
  • junit.xml — CI/JUnit output
  • playwright-report/ — visual HTML report
  • test-results/<test>/trace.zip — Playwright trace

The MCP server exposes tools for listing specs, running tests, reading results, analyzing failures, generating test previews, selecting impacted tests, and proposing/validating guarded locator repairs.

Start it locally:

npm run mcp:server

For AI-assisted debugging:

  1. Run the smallest failing spec.
  2. Read test-results/ai-report.json.
  3. Open the trace or screenshot when available.
  4. Update the locator in the relevant tests/pages/*Page.ts.
  5. Re-run the spec and the smallest related suite.

Healing tools are intentionally POM-only. Applying locator changes may require approval according to risk, and validation should compare the rerun before and after.

AI terminology

Capabilities and connections

  • Skills: reusable instruction files or modular capabilities that teach an AI how to perform a specific, repeatable task on demand.
  • Tool use (function calling): the ability of an AI model to interact with external software, such as searching the web, querying a database, or sending an email, instead of only generating text.
  • MCP (Model Context Protocol): an open standard that acts like a USB-C port for AI, allowing models to connect to external applications and data sources, such as Google Drive, Notion, or Jira, without custom code for each integration.
  • RAG (Retrieval-Augmented Generation): a technique that retrieves relevant facts from private documents or a database before answering, keeping responses grounded in real data.

Safety and control

  • Guardrails: programmable rules and filters around AI inputs, outputs, and tool actions that block harmful content, prevent data leaks, and keep the system on topic.
  • Prompt injection: a security attack where a user disguises malicious instructions inside normal text to trick the AI into ignoring its rules or leaking sensitive data.
  • Hallucination: when an AI confidently invents false facts, fake citations, or made-up events because it predicts plausible-sounding words rather than checking truth.
  • Evals (evaluations): automated tests and scorecards used to measure whether an AI system is accurate, safe, and reliable before and after updates.

Autonomy and workflows

  • AI agent: a system that combines an AI model with memory and tools so it can plan, make decisions, and take multiple steps toward a goal.
  • Orchestration: the traffic-controller layer that coordinates multiple prompts, tools, or sub-agents so they run in the correct order.
  • Context engineering: the practice of dynamically supplying the AI with the exact background information, rules, and examples needed at the right moment.
  • Loops: instructions that require an AI to review its own output against a checklist, catch mistakes, and revise the work before showing it to the user.

Playwright agents

The repository provides three modern custom agents in .github/agents/:

  • playwright-planner: explores a journey and produces a risk-based test plan.
  • playwright-generator: converts a plan into POM-aligned Playwright specs.
  • playwright-healer: reproduces failures and repairs the smallest root cause.

Agent example: select playwright-generator and enter:

Generate a deterministic Chromium smoke spec for https://indiarealtime.com.
Verify the homepage, capture accessibility basics, and open the first article.
Put UI locators in tests/pages/IndiaRealTimePage.ts and use tests/data/urls.ts.
Run npm run test:smoke after generation.

The same agent workflow supports 2026/2027 maintenance:

  1. Plan new journeys and classify regression risk.
  2. Generate independent, project-compatible specs.
  3. Run focused browser checks in Chromium, Firefox, WebKit, and mobile projects.
  4. Heal only reproduced failures and validate the affected suite.
  5. Consume the AI report and trace before changing assertions or locators.

Configuration

Variable Default Purpose
E2E_BASE_URL https://indiarealtime.com Base URL for browser and API fixtures
E2E_API_TOKEN unset Optional bearer token for API requests
CI unset Enables CI retries and worker limits

Authentication and sensitive values should remain in environment variables or CI secrets. The framework redacts secrets in AI report output and healing records.

Browser and device coverage

The default configuration includes Chromium, Firefox, WebKit, Mobile Chrome (Pixel 5), and Mobile Safari (iPhone 12).

npx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkit
npx playwright test tests/mobile.spec.ts --project="Mobile Chrome"
npx playwright test tests/mobile.spec.ts --project="Mobile Safari"

Install all browsers once with:

npx playwright install --with-deps

Docker

docker-compose up --build tests

Override the target by updating docker-compose.yml or passing E2E_BASE_URL in the local environment. Docker output is written to mounted Playwright and test-result directories.

CI/CD

GitHub Actions runs formatting, unit, integration, smoke, security/audit, and secret-scanning checks. Unit and integration suites remain blocking; extended suites are clearly separated for faster feedback.

CI artifacts include HTML reports, JSON/JUnit results, traces, screenshots, and videos.

Test coverage areas

  • End-to-end smoke flows
  • API operations and contract checks
  • Authentication and XSS checks
  • Accessibility and keyboard behavior
  • Broken links, invalid routes, and input validation
  • Mobile and internationalization behavior
  • Network/offline resilience
  • Performance load-time checks
  • Interoperability and mock scenarios
  • Chaos/concurrency and resource failure checks

Troubleshooting

Problem Fix
Browsers missing npx playwright install --with-deps
Locator changed Inspect test-results/error-context.md or the trace, then update the POM
Target unavailable Set E2E_BASE_URL and verify network/DNS access
MCP server unavailable Run npm ci && npm run mcp:server
Formatting fails npm run format
Type failures npm run typecheck

Debug a single spec:

npx playwright test tests/indiaRealtime.spec.ts --project=chromium --headed --debug
npx playwright show-trace test-results/<test-name>/trace.zip
npx playwright show-report

License

MIT. See LICENSE.

Explore related projects

Loading…