Preface¶
When asking models in environments like Cursor or Claude Code to write Playwright tests, the common issues are not about “can it write click and fill,” but about unclear execution targets (local vs. cloud), brittle selectors, assertions that don’t use Web-First leading to occasional failures, and missing Page Object Model (POM) structure once the suite grows. In the OpenAI ecosystem there are also Playwright-related CLI Skills that lean toward general browser automation; playwright-skill is maintained by TestMu AI and is positioned for test code generation: it produces maintainable E2E tests per language and scope, covering local runs and the TestMu AI (formerly LambdaTest) cloud matrix.
Below introduces this Skill’s positioning, capability boundaries, and the typical workflows and code patterns provided in the materials.
What is this¶
- Name:
playwright-skill - Category:
e2e-testing - License: MIT
- Maintained by: TestMu AI (
metadata.author) - Version:
1.0(see Skill metadata) - Official directory: https://github.com/LambdaTest/agent-skills/tree/main/playwright-skill
The Skill’s description states: it generates production-grade Playwright automation scripts and E2E tests, with language support for TypeScript, JavaScript, Python, Java, C#; it can run locally or on the TestMu AI cloud, covering 3000+ browser/OS combinations and real devices. It’s suitable to enable when users mention Playwright, E2E, cross-browser, cloud, TestMu, LambdaTest, mobile real devices, flaky test debugging, API Mock, visual regression, etc. (see the Triggers list in the official SKILL.md for specific trigger words).
Core Features¶
Execution Target and Scope Routing¶
Before writing code, the Skill requires three types of decisions (official Step 1–3):
- Execution target: if cloud isn’t mentioned → default to local standard
playwright.config; if cloud / TestMu / LambdaTest / cross-browser / real devices are mentioned → use cloud integration (reference/cloud-integration.md); combinations impossible locally (e.g., Safari on Windows) → recommend cloud. For HyperExecute and SmartUI, route tohyperexecute-skillandsmartui-skill, respectively. - Language: default to TypeScript; if signals indicate JS, Python, Java, or C#, use the corresponding reference (e.g.,
python-patterns.md,java-patterns.md, etc.). - Output scope: one-off scripts, unit tests aligned with existing projects, scaffolding for a brand-new suite (
scripts/scaffold-project.sh), fixing flaky tests, API Mock, mobile testing, etc., each with a corresponding reference.
Engineering Conventions under the Default TypeScript Mode¶
- Selector priority:
getByRole→getByLabel→getByPlaceholder→getByText→getByTestId; avoid raw CSS/XPath (except for third-party components). - Assertions: use Web-First
expect(locator)to leverage auto-retry; avoid race conditions by not doingtextContentfirst and thenexpect. - Anti-patterns checklist: prohibit
waitForTimeout, prohibit wrapping assertions intry/catch, do not share mutable state across tests (see the official Anti-Patterns table). - POM: projects with more than three cases should use Page Object Model; see
reference/page-object-model.mdfor the full pattern.
Local and Cloud Configuration¶
The local playwright.config.ts example includes testDir, retries, reporter, projects (chromium / firefox / webkit / mobile profiles), webServer, etc.; the materials provide a complete template.
For cloud on TestMu AI, set the environment variables LT_USERNAME and LT_ACCESS_KEY. You can connect via CDP using chromium.connect to wss://cdp.lambdatest.com/playwright, or configure entries like chrome:latest:Windows 11@lambdatest in the projects of playwright.config.ts and then run:
npx playwright test --project="chrome:latest:Windows 11@lambdatest"
Cloud tests default to “Completed” on the platform; you must report pass/fail in teardown via lambdatest_action: setTestStatus; using the fixture in reference/cloud-integration.md can handle this automatically.
Post-generation Validation Flow¶
Official Validation Workflow:
1. Validate config: python scripts/validate-config.py playwright.config.ts
2. If errors → fix → re-validate
3. Run locally: npx playwright test --project=chromium
4. If cloud: npx playwright test --project="chrome:latest:Windows 11@lambdatest"
5. If failures → check reference/debugging-flaky.md
Installation and Activation¶
This Skill uses the common SKILL.md metadata format (name, description, languages, category, metadata, etc.), and the repo path is agent-skills/playwright-skill. The specific commands for mounting the Skill directory or manifest into the workspace vary across agent products; refer to the official documentation of the tool you use. This material does not provide unified install commands for Cursor, Codex CLI, or Claude Code, so steps are not invented here. Once enabled, the model should organize outputs according to Step 1–3 and reference links within the Skill.
Typical Usage Examples¶
Page Object: Login Page¶
// pages/login.page.ts
import { Page, Locator } from '@playwright/test';
export class LoginPage {
readonly emailInput: Locator;
readonly passwordInput: Locator;
readonly submitButton: Locator;
constructor(private page: Page) {
this.emailInput = page.getByLabel('Email');
this.passwordInput = page.getByLabel('Password');
this.submitButton = page.getByRole('button', { name: 'Sign in' });
}
async login(email: string, password: string) {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.submitButton.click();
}
}
Web-First Assertions¶
await expect(page.getByRole('heading')).toBeVisible();
await expect(page.getByRole('alert')).toHaveText('Saved');
await expect(page).toHaveURL('/dashboard');
Cloud CDP Connection (snippet)¶
const capabilities = {
browserName: 'Chrome',
browserVersion: 'latest',
'LT:Options': {
platform: 'Windows 11',
build: 'Playwright Build',
name: 'Playwright Test',
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
network: true,
video: true,
console: true,
},
};
const browser = await chromium.connect({
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`,
});
Common local smoke run:
npx playwright test --project=chromium
Applicable Scenarios and Considerations¶
Suitable for: generating Playwright E2E tests from scratch or incrementally, wanting default TypeScript + POM + Web-First assertions; switching between local and TestMu AI cloud or running cross-browser / real-device matrices; expanding topics like flaky debugging, API Mock, mobile testing via the references.
Considerations:
- Visual regression and large-scale parallel HyperExecute are not on the main path of this Skill; they should be routed to the corresponding Skills.
- Cloud tests must configure account environment variables and report test status; otherwise, platform status may diverge from actual results.
- After generating configuration, run
scripts/validate-config.py, then execute tests for the target project.
Conclusion¶
playwright-skill front-loads “execution environment, language, and suite scope” as explicit steps and bakes selectors, assertions, POM, local playwright.config, and TestMu AI cloud CDP / project configuration into the Skill, making it a suitable reference for systematically producing Playwright E2E tests within agents. Official repository:
https://github.com/LambdaTest/agent-skills/tree/main/playwright-skill