All skills
fugazi avatar

/playwright-e2e-testing

@96feaff

Author and maintain versioned Playwright (@playwright/test) TypeScript UI specs for browser user flows. Use when asked to create, run, debug, or refactor E2E tests, form/navigation/auth flows, responsive checks, UI mocking, fixtures, Page Objects, or visual comparisons. Use api-testing for standalone REST/GraphQL contracts and playwright-cli for live browser sessions. Keywords: E2E spec, Playwright test, POM, fixtures, UI regression.

Use this Skill: https://skilld.dev/gh/fugazi/test-automation-skills-agents/playwright-e2e-testing

This session only. Nothing lands on disk.

referenceslocator-strategies-anti-debug.md

≈894 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Locator Strategies: Anti-Patterns, CSS Last-Resort & Debugging

Part of the playwright-e2e-testing skill. See SKILL.md for full context.

Related: this file was split from the original locator-strategies.md. See the other locator-strategies-*.md files in this folder for related sections.

Anti-Patterns to Avoid

[no] CSS Selectors (Brittle)

// Bad - class names change frequently
page.locator(".btn-primary.submit-form");
page.locator("#submit-button");
page.locator('[class*="Button"]');

[no] Complex XPath

// Bad - extremely brittle
page.locator(
  '//div[@class="container"]//form//button[contains(text(), "Submit")]',
);
page.locator("//table/tbody/tr[3]/td[2]/a");

[no] Index Without Context

// Bad - which button? Why index 3?
page.locator("button").nth(3);

[ok] Correct Alternatives

// Good - use role-based
page.getByRole("button", { name: "Submit" });

// Good - filter then index
page
  .getByRole("row")
  .filter({ hasText: "Product A" })
  .getByRole("button")
  .first();

// Good - chain from container
page.getByRole("dialog").getByRole("button", { name: "Submit" });

CSS Locator (Last Resort)

When semantic locators aren't available:

// By class (less brittle with data attributes)
page.locator('[data-state="active"]');
page.locator('[aria-expanded="true"]');

// By attribute
page.locator('input[type="file"]');
page.locator('a[href*="download"]');

// Child/descendant
page.locator("nav >> a"); // descendant
page.locator("ul > li"); // direct child

// Combining with text
page.locator('button:has-text("Submit")');
page.locator('div:text-is("Exact match")');

// Pseudo-selectors
page.locator("input:visible");
page.locator("button:enabled");

Debugging Locators

Playwright Inspector

# Launch with Inspector
PWDEBUG=1 npx playwright test

# Or in UI mode
npx playwright test --ui

Codegen

# Record interactions and see locators
npx playwright codegen http://localhost:3000

Browser DevTools

// In browser console
document.querySelector('[data-testid="submit"]');
document.querySelectorAll('[role="button"]');

// Test accessibility tree
$0; // Select element, then inspect in Accessibility panel

In-Test Debugging

// Highlight element before interacting
await page.getByRole("button", { name: "Submit" }).highlight();

// Log matched elements count
const count = await page.getByRole("listitem").count();
console.log(`Found ${count} list items`);

// Pause for inspection
await page.pause();

Quick Reference

Need Locator
Button by text getByRole('button', { name: 'Click' })
Input by label getByLabel('Email')
Link by text getByRole('link', { name: 'Home' })
Heading getByRole('heading', { name: 'Title' })
Checkbox getByRole('checkbox', { name: 'Agree' })
First in list getByRole('listitem').first()
In container getByRole('dialog').getByRole('button')
Table row getByRole('row').filter({ hasText: 'John' })
By test ID getByTestId('custom-element')
Placeholder getByPlaceholder('Search...')
Image alt getByAltText('Logo')

Source: SKILL.md on GitHub

1 warning16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    No security issues detected. The skill provides standard and safe instructions for authoring Playwright E2E tests, following best practices for locator usage and Page Object Model implementation.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    3/5 files flagged

Signed by skilld at 96feaff. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 2 months ago

README badge

README badge for fugazi/test-automation-skills-agents/playwright-e2e-testing