playwright-test-generator
Generate production-ready Playwright E2E tests from natural language specifications or requirements. Creates TypeScript test files following best practices including data-testid locators, proper async/await usage, test isolation, and the AAA (Arrange-Act-Assert) pattern.
What this skill does
## When to Use This Skill
Use this skill when you need to:
- Create new E2E tests from user stories or requirements
- Generate test files for new features or pages
- Convert manual test cases into automated tests
- Scaffold a complete test suite for a new application
- Create tests with proper fixtures and configuration
Do NOT use this skill when:
- You need to debug existing tests (use test-debugger skill)
- You want to refactor or maintain existing tests (use test-maintainer skill)
- You need to create Page Object Models (use page-object-builder skill)
## Prerequisites
Before using this skill:
1. Playwright should be installed in the project (`npm install -D @playwright/test`)
2. Basic understanding of the application under test (URLs, main flows)
3. Knowledge of what functionality needs to be tested
4. Access to the application's UI or design documentation
## Instructions
### Step 1: Gather Test Requirements
Ask the user for:
- **Feature/functionality** to test
- **User flow** or scenario description
- **Expected outcomes** (what should happen)
- **Test data** requirements (if any)
- **Page URL(s)** involved in the test
- **Data-testid values** (or offer to suggest them based on element purpose)
### Step 2: Analyze and Plan
Review the requirements and:
- Break down the user flow into discrete steps
- Identify all page elements that need interaction
- Determine what assertions are needed
- Plan the test structure (setup, actions, verifications)
- Identify any fixtures or utilities needed
### Step 3: Generate Test File
Create a TypeScript test file with:
**File Structure:**
```typescript
import { test, expect } from "@playwright/test";
test.describe("Feature Name", () => {
test("should <specific behavior>", async ({ page }) => {
// Arrange: Setup
// Act: Perform actions
// Assert: Verify results
});
});
```
**Required Elements:**
- Descriptive test names (what behavior is tested)
- Proper async/await usage
- data-testid locators ONLY
- Explicit waits (waitForSelector, waitForLoadState)
- Clear assertions with expect()
- Comments for AAA sections
- TypeScript types
**Locator Strategy (MANDATORY):**
```typescript
// ✅ CORRECT: Always use data-testid
await page.locator('[data-testid="submit-button"]').click();
await expect(page.locator('[data-testid="success-message"]')).toBeVisible();
// ❌ WRONG: Never use CSS selectors, XPath, or text selectors
await page.locator(".submit-btn").click(); // NO
await page.locator('//button[@type="submit"]').click(); // NO
await page.getByRole("button", { name: "Submit" }).click(); // NO
```
### Step 4: Add Configuration (if needed)
If this is the first test, generate `playwright.config.ts`:
- Base URL configuration
- Timeout settings (30s default)
- Retry logic (2 retries for flaky tests)
- Screenshot on failure
- Trace on first retry
- Parallel execution settings
### Step 5: Include Fixtures (if needed)
For complex setups, create custom fixtures:
```typescript
import { test as base } from "@playwright/test";
type MyFixtures = {
authenticatedPage: Page;
};
export const test = base.extend<MyFixtures>({
authenticatedPage: async ({ page }, use) => {
// Setup: login
await page.goto("/login");
await page.locator('[data-testid="username"]').fill("testuser");
await page.locator('[data-testid="password"]').fill("password");
await page.locator('[data-testid="login-button"]').click();
await page.waitForURL("/dashboard");
await use(page);
// Teardown (if needed)
},
});
```
### Step 6: Validate Generated Test
Ensure the test includes:
- [ ] Descriptive test name
- [ ] Proper test.describe grouping
- [ ] Only data-testid locators
- [ ] No hardcoded waits (no page.waitForTimeout())
- [ ] Explicit waits for elements
- [ ] Clear AAA structure
- [ ] TypeScript types
- [ ] Meaningful assertions
- [ ] Comments for complex logic
### Step 7: Provide Usage Instructions
Tell the user:
- Where the test file was created
- How to run the test: `npx playwright test <filename>`
- How to run in debug mode: `npx playwright test --debug <filename>`
- How to view traces: `npx playwright show-trace trace.zip`
- What data-testid values need to be added to the UI (if suggesting new ones)
## Examples
### Example 1: Simple Login Test
**Input:**
"Create a test for the login flow. User enters username and password, clicks login button, and should see the dashboard."
**Output:**
```typescript
import { test, expect } from "@playwright/test";
test.describe("Authentication", () => {
test("should successfully login with valid credentials", async ({ page }) => {
// Arrange: Navigate to login page
await page.goto("/login");
await expect(page.locator('[data-testid="login-form"]')).toBeVisible();
// Act: Enter credentials and submit
await page
.locator('[data-testid="username-input"]')
.fill("[email protected]");
await page.locator('[data-testid="password-input"]').fill("SecurePass123");
await page.locator('[data-testid="login-button"]').click();
// Assert: Verify successful login
await page.waitForURL("/dashboard");
await expect(
page.locator('[data-testid="dashboard-header"]'),
).toBeVisible();
await expect(page.locator('[data-testid="user-welcome"]')).toContainText(
"Welcome",
);
});
});
```
**Required data-testid values:**
- `login-form` - The login form container
- `username-input` - Username/email input field
- `password-input` - Password input field
- `login-button` - Submit button
- `dashboard-header` - Dashboard page header
- `user-welcome` - Welcome message element
### Example 2: E-commerce Product Purchase
**Input:**
"Test the product purchase flow: search for 'laptop', select first result, add to cart, checkout, and verify order confirmation."
**Output:**
```typescript
import { test, expect } from "@playwright/test";
test.describe("E-commerce Purchase Flow", () => {
test("should complete product purchase from search to confirmation", async ({
page,
}) => {
// Arrange: Navigate to homepage
await page.goto("/");
await expect(page.locator('[data-testid="search-bar"]')).toBeVisible();
// Act: Search for product
await page.locator('[data-testid="search-input"]').fill("laptop");
await page.locator('[data-testid="search-button"]').click();
await page.waitForLoadState("networkidle");
// Act: Select first product
await expect(
page.locator('[data-testid="product-card"]').first(),
).toBeVisible();
await page.locator('[data-testid="product-card"]').first().click();
// Act: Add to cart
await expect(
page.locator('[data-testid="add-to-cart-button"]'),
).toBeEnabled();
await page.locator('[data-testid="add-to-cart-button"]').click();
await expect(page.locator('[data-testid="cart-count"]')).toContainText("1");
// Act: Proceed to checkout
await page.locator('[data-testid="cart-icon"]').click();
await page.locator('[data-testid="checkout-button"]').click();
// Act: Fill checkout form
await page.locator('[data-testid="shipping-name"]').fill("John Doe");
await page.locator('[data-testid="shipping-address"]').fill("123 Main St");
await page.locator('[data-testid="shipping-city"]').fill("New York");
await page.locator('[data-testid="shipping-zip"]').fill("10001");
await page.locator('[data-testid="payment-card"]').fill("4242424242424242");
await page.locator('[data-testid="payment-expiry"]').fill("12/25");
await page.locator('[data-testid="payment-cvc"]').fill("123");
await page.locator('[data-testid="place-order-button"]').click();
// Assert: Verify order confirmation
await page.waitForURL(/\/order\/confirmation/);
await expect(
page.locator('[data-testid="order-success-message"]'),
).toBeVisible();
await expect(page.locator('[data-testid="order-number"]')).toContainText(
/ORD-\d+/,
);
});
});
```
### ExampleRelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.