Skip to content

chore: Add AI agent roles, skills inventory, and Copilot instructions for Playwright framework#62

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/setup-ai-agents-playwright
Draft

chore: Add AI agent roles, skills inventory, and Copilot instructions for Playwright framework#62
Copilot wants to merge 3 commits intomainfrom
copilot/setup-ai-agents-playwright

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 1, 2026

Standardises the repo for AI-assisted development by adding structured guidance for MCP-enabled editors and GitHub Copilot, grounded in the actual project structure (playwright.config.ts, tests/pageobjects/, CI workflow).

New files

  • AGENTS.md — Defines three MCP agent roles with concrete CLI commands and project-specific context:

    • CLI Automator--debug, --ui, codegen, show-trace, --last-failed
    • Locator Optimizer — maps existing XPath/CSS selectors in login.ts / tasks.ts to their getByRole/getByLabel/getByPlaceholder equivalents; locator priority aligned across all docs (getByRolegetByLabelgetByPlaceholdergetByTextgetByTestId → CSS)
    • CI/CD Engineer — sharding, worker tuning, trace artifact uploads, report merging
    • Includes a Skills Reference table linking to .agents/skills/
  • .agents/skills/ — Three project-agnostic, generalist skill files following Anthropic's standard structure (replacing the root SKILLS.md):

    • playwright-cli-tooling.md — running, debugging, recording, and inspecting tests via the Playwright CLI
    • web-first-assertions.md — auto-retrying expect assertions for DOM, URL, and API state
    • network-interception.md — mocking, aborting, and inspecting network requests with page.route()
  • .github/copilot-instructions.md — Copilot golden rules:

    • page.$() and XPath chains disallowed in this repository; enforces 6-level locator priority
    • New Page Pattern (browser.newPage()) forbidden in UI tests; tests/a11y.lighthouse.spec.ts documented as an explicit exception (required for Lighthouse remote-debugging port)
    • Web-first expect assertions only; no waitForTimeout()
    • CLI-first debugging (inspect trace before adding retries)
    • No hard-coded credentials; .env + GitHub Actions secrets

Updated

  • README.md — Adds a Playwright CLI Guide section (--ui, --debug, codegen, show-trace, sharding) and an MCP Integration section with agent table, local setup steps, example prompts, and cross-links to the new docs.

Removed

  • SKILLS.md (root) — replaced by the agnostic per-skill files under .agents/skills/.
Original prompt

This section details on the original issue you should resolve

<issue_title>[Chore] Setup AI Agents, Skills and Copilot Instructions for Playwright Framework</issue_title>
<issue_description>"Actúa como un Principal SDET Architect. Tu misión es estandarizar este repositorio de Playwright + TypeScript utilizando el Playwright CLI y capacidades de MCP para el desarrollo asistido por IA.

🔍 PASO 1: Análisis Dinámico con Playwright CLI (Obligatorio)
Antes de redactar, utiliza las herramientas del sistema para realizar una introspección profunda:

  • Configuración: Analiza playwright.config.ts. Identifica proyectos, baseURL y el uso de storageState.
  • Exploración de UI (CLI): Usa npx playwright codegen --target typescript (o simula su lógica) para identificar los Locators más estables (priorizando getByRole, getByLabel y data-testid).
  • Análisis de Fixtures: Busca en tests/ o src/fixtures/ cómo se extiende el objeto test.
  • Dependencias: Revisa el package.json para validar versiones de @playwright/test y plugins adicionales.
    📄 PASO 2: Generación de Documentos (En la raíz del proyecto)
    Crea los siguientes archivos basándote estrictamente en el análisis previo:
  • AGENTS.md (Raíz): Define roles que aprovechen el MCP:
    • CLI Automator Agent: Experto en usar npx playwright test --debug y codegen para diagnosticar fallos.
    • Locator Optimizer: Especialista en convertir selectores CSS/XPath frágiles en Locators de Playwright resilientes.
    • CI/CD Engineer: Enfocado en la ejecución en paralelo y gestión de sharding.
  • SKILL.md (Raíz): Inventario de capacidades técnicas:
    • Tooling: Uso del Playwright CLI para inspección de trazas (npx playwright show-trace).
    • Assertions: Implementación de Web-first assertions asíncronas.
    • Network: Intercepción de red y mocking con page.route.
  • .github/copilot-instructions.md: Reglas de oro para Copilot:
    • Uso de Herramientas: Siempre sugerir el uso de npx playwright comandos para tareas de debugging.
    • Locators Modernos: Prohibido el uso de page.$(...). Forzar el uso de la API de Locators.
    • Estructura de Test: Seguir el patrón de Fixtures detectado para evitar el 'New Page Pattern'.
      📝 PASO 3: Actualización del README.md
      Integra una guía de uso del Playwright CLI específica para este proyecto:
  • Instrucciones para abrir el UI Mode (npx playwright test --ui).
  • Cómo generar tests rápidos con codegen.
  • Sección de MCP Integration para que otros desarrolladores sepan cómo la IA asiste en la creación de localizadores.
    Entregable: Proporciona los bloques Markdown para cada archivo, asegurando que reflejen la estructura de carpetas real que has detectado."</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…EADME with CLI guide and MCP section

Co-authored-by: charlyautomatiza <89928062+charlyautomatiza@users.noreply.github.com>
Copilot AI changed the title [WIP] Setup AI agents and skills for Playwright framework chore: Add AI agent roles, skills inventory, and Copilot instructions for Playwright framework Mar 1, 2026
@charlyautomatiza charlyautomatiza requested a review from Copilot March 1, 2026 01:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds repository-specific guidance to standardize AI-assisted development and Playwright testing practices, aligning MCP-enabled workflows and GitHub Copilot suggestions with the project’s Playwright config, POM structure, and CI setup.

Changes:

  • Add AGENTS.md defining MCP-oriented agent roles (CLI Automator, Locator Optimizer, CI/CD Engineer).
  • Add SKILLS.md documenting established Playwright/TypeScript patterns, tooling, reporting, network mocking, and dependencies.
  • Add .github/copilot-instructions.md plus README sections for CLI usage and MCP integration cross-links.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
SKILLS.md New “skills inventory” documentation for CLI, assertions, network patterns, POM/fixtures, env vars, a11y, dependencies
AGENTS.md New agent-role definitions with project-specific commands and locator strategy guidance
.github/copilot-instructions.md New Copilot rules for locators, test structure, assertions, reporting, and security
README.md Adds Playwright CLI guide + MCP Integration section linking to the new docs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

SKILLS.md Outdated

- `page.waitForTimeout()` – flaky; use web-first assertions instead.
- `page.waitForSelector()` – replaced by locator auto-waiting.
- `element.innerText()` for assertions – use `expect(locator).toHaveText()` instead.
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section says element.innerText() should be avoided for assertions, but the current Tasks.getTaskTitle() implementation returns innerText() and is used in assertions (e.g., tests/api.ui.spec.ts). Since this file is positioned as an inventory of established patterns, consider rephrasing to “prefer”/“migrate towards” web-first locator assertions, or align the codebase first and then document it as established.

Suggested change
- `element.innerText()` for assertions – use `expect(locator).toHaveText()` instead.
- Prefer `expect(locator).toHaveText()` over using `element.innerText()` for assertions; legacy `innerText()` usages should be migrated over time.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a4c3ba3. The innerText() guidance has been moved to the agnostic .agents/skills/web-first-assertions.md with the accurate phrasing: "Avoid extracting values with locator.innerText() / locator.textContent() and then asserting on them; this creates a race condition. Use expect(locator).toHaveText() instead." — reflecting it as a migration target rather than a current project standard.

AGENTS.md Outdated
Comment on lines +55 to +56
4. `getByText` / `getByTestId` – for content or custom `data-testid` attributes
5. `locator('css')` – only when no semantic alternative exists
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The locator priority list here groups getByText / getByTestId together, but .github/copilot-instructions.md later defines them as separate priorities (text before test id). To avoid conflicting guidance, align the ordering between the docs (either split these into distinct priorities here or adjust the other doc).

Suggested change
4. `getByText` / `getByTestId` – for content or custom `data-testid` attributes
5. `locator('css')` – only when no semantic alternative exists
4. `getByText` – for visible user-facing text content
5. `getByTestId` – for custom `data-testid` attributes when semantic/text options are not suitable
6. `locator('css')` – only when no semantic alternative exists

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned in a4c3ba3. AGENTS.md now lists getByText and getByTestId as separate priorities (4 and 5), matching the order in copilot-instructions.md.


## 🔍 Modern Locators (mandatory)

- **Prohibited:** `page.$()`, `page.$$()`, `page.$eval()`, `page.$$eval()`. These are deprecated and must not be used.
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playwright’s page.$() / $eval() APIs are still supported; calling them “deprecated” is inaccurate and may confuse readers. If the intent is to ban them in this repo, consider rewording to “disallowed in this repository (prefer Locator API for stability)” without claiming deprecation.

Suggested change
- **Prohibited:** `page.$()`, `page.$$()`, `page.$eval()`, `page.$$eval()`. These are deprecated and must not be used.
- **Prohibited:** `page.$()`, `page.$$()`, `page.$eval()`, `page.$$eval()`. These are disallowed in this repository; prefer the Locator API for stability and consistency.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a4c3ba3. Changed to: "These are disallowed in this repository; prefer the Locator API for stability and consistency."

Comment on lines +59 to +72
- **Fixtures pattern:** Do NOT instantiate `new Page()` or call `browser.newPage()` inside tests. Always receive `page` through the test fixture parameter:
```typescript
// ❌ New Page Pattern – avoid
test('my test', async ({ browser }) => {
const page = await browser.newPage();
// ...
});

// ✅ Fixture pattern – always use this
test('my test', async ({ page }) => {
const login = new Login(page);
// ...
});
```
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule forbids browser.newPage() inside tests, but tests/a11y.lighthouse.spec.ts currently launches Chromium manually and uses browser.newPage() (required for Lighthouse flow). To keep repo guidance internally consistent, scope this rule to UI tests using @playwright/test fixtures (or explicitly document the a11y/Lighthouse exception).

Suggested change
- **Fixtures pattern:** Do NOT instantiate `new Page()` or call `browser.newPage()` inside tests. Always receive `page` through the test fixture parameter:
```typescript
// ❌ New Page Pattern – avoid
test('my test', async ({ browser }) => {
const page = await browser.newPage();
// ...
});
// ✅ Fixture pattern – always use this
test('my test', async ({ page }) => {
const login = new Login(page);
// ...
});
```
- **Fixtures pattern (UI tests):** For UI tests using `@playwright/test` fixtures, do NOT instantiate `new Page()` or call `browser.newPage()` inside tests. Always receive `page` through the test fixture parameter:
```typescript
// ❌ New Page Pattern – avoid (UI tests)
test('my test', async ({ browser }) => {
const page = await browser.newPage();
// ...
});
// ✅ Fixture pattern – always use this in UI tests
test('my test', async ({ page }) => {
const login = new Login(page);
// ...
});

Note: tests/a11y.lighthouse.spec.ts is an intentional exception. Lighthouse flows manually launch Chromium and use browser.newPage(); this is allowed there but should not be copied into regular UI tests.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a4c3ba3. The rule is now scoped to "UI tests using @playwright/test fixtures" with an explicit callout: tests/a11y.lighthouse.spec.ts intentionally uses browser.newPage() for the Lighthouse remote-debugging port — this is allowed there and must not be copied into regular UI tests.

README.md Outdated
Comment on lines +133 to +138
npx playwright codegen $BASE_URL
# Use the baseURL configured in playwright.config.ts
# e.g. https://charlyautomatiza.github.io/task-management-frontend

Opens a browser with a recorder panel. Every click, fill, and navigation is transcribed into TypeScript code that you can paste directly into a spec file.

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npx playwright codegen $BASE_URL assumes a BASE_URL env var, but the repo doesn’t define it (and Playwright’s config use.baseURL is set directly). Consider either using the literal URL from playwright.config.ts, or documenting how to set BASE_URL (e.g., via .env) so this command works as written.

Suggested change
npx playwright codegen $BASE_URL
# Use the baseURL configured in playwright.config.ts
# e.g. https://charlyautomatiza.github.io/task-management-frontend
Opens a browser with a recorder panel. Every click, fill, and navigation is transcribed into TypeScript code that you can paste directly into a spec file.
npx playwright codegen https://charlyautomatiza.github.io/task-management-frontend
# Replace the URL above with the baseURL configured in your playwright.config.ts (use.baseURL)
Opens a browser with a recorder panel. Every click, fill, and navigation is transcribed into TypeScript code that you can paste directly into a spec file.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a4c3ba3. Replaced $BASE_URL with the actual URL from playwright.config.ts and added a comment explaining where to find the value: # Replace the URL above with the baseURL configured in your playwright.config.ts (use.baseURL).

SKILLS.md Outdated
Comment on lines +87 to +95
Direct API calls are made using `playwright.request.newContext()`. The `baseURL` for the API is set per-context (see `tests/global.setup.ts` and `tests/api.ui.spec.ts`; the URL is stored as `process.env.API_BASE_URL` or hard-coded in those files and must be moved to `.env` for different environments). The pattern used in this project:

```typescript
let apiContext: APIRequestContext;

test.beforeEach(async ({ playwright }) => {
apiContext = await playwright.request.newContext({
baseURL: 'https://task-mgmt-charlyautomatiza.onrender.com',
extraHTTPHeaders: { Accept: 'application/json' },
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.API_BASE_URL is referenced here as an existing pattern, but it doesn’t appear anywhere else in the repo (all current API contexts hard-code https://task-mgmt-charlyautomatiza.onrender.com). Either update this doc to reflect the current state, or actually introduce and document an API_BASE_URL env var (and use it in tests/global.setup.ts / API specs).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a4c3ba3. The project-specific APIRequestContext documentation (which referenced the non-existent process.env.API_BASE_URL) has been removed from the root. The generalist .agents/skills/network-interception.md now shows the correct pattern using process.env.API_BASE_URL ?? 'https://your-api.example.com' as a documented best-practice placeholder.

@charlyautomatiza
Copy link
Copy Markdown
Owner

.agents/skills/ es la ruta correcta para las skills @copilot por otra parte quiero que la skill sea agnóstica, sea generalista y no atada al contexto específico de este proyecto.

Tiene que seguir la estructura y patrón estándar de Anthropic

…ors, assertions and codegen URL

Co-authored-by: charlyautomatiza <89928062+charlyautomatiza@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 1, 2026

.agents/skills/ es la ruta correcta para las skills @copilot por otra parte quiero que la skill sea agnóstica, sea generalista y no atada al contexto específico de este proyecto.

Tiene que seguir l...

Done in a4c3ba3. Removed SKILLS.md from the root and created three project-agnostic skill files under .agents/skills/ following Anthropic's standard structure:

  • .agents/skills/playwright-cli-tooling.md
  • .agents/skills/web-first-assertions.md
  • .agents/skills/network-interception.md

Each skill is self-contained, generalist, and carries no project-specific context. AGENTS.md now includes a Skills Reference table linking to the new path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore] Setup AI Agents, Skills and Copilot Instructions for Playwright Framework

3 participants