playwright

Playwright end-to-end testing best practices for web applications, covering test design, locator strategies, and assertion patterns.

INSTALLATION
npx skills add https://github.com/mindrally/skills --skill playwright
Run in your project or agent environment. Adjust flags if your CLI version differs.

SKILL.md

$27

test('should login successfully with valid credentials', async ({ page }) => {

await page.getByLabel('Email').fill('user@example.com');

await page.getByLabel('Password').fill('password123');

await page.getByRole('button', { name: 'Sign In' }).click();

await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();

});

});

## Locator Strategy

### Recommended Locators

- `page.getByRole()` - Best for accessibility and user perspective

- `page.getByLabel()` - For form inputs with labels

- `page.getByText()` - For elements with visible text

- `page.getByTestId()` - When `data-testid` attributes exist

- `page.getByPlaceholder()` - For inputs with placeholder text

// Recommended

await page.getByRole('button', { name: 'Submit' }).click();

await page.getByLabel('Email address').fill('test@example.com');

// Avoid

await page.locator('.btn-primary').click();


## Assertions and Waits

### Web-First Assertions

Prefer web-first assertions that automatically wait and retry:

- `toBeVisible()` - Element is visible

- `toHaveText()` - Element has specific text

- `toHaveValue()` - Input has specific value

- `toHaveURL()` - Page URL assertion

// Recommended - web-first assertions

await expect(page.getByRole('alert')).toBeVisible();

await expect(page).toHaveURL('/dashboard');

// Avoid - hardcoded timeouts

await page.waitForTimeout(5000); // Never do this


### Waiting Best Practices

- Avoid hardcoded timeouts

- Use `page.waitForLoadState()` for navigation

- Use `page.waitForResponse()` for API calls

## Configuration

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({

testDir: './tests',

fullyParallel: true,

retries: process.env.CI ? 2 : 0,

use: {

baseURL: 'http://localhost:3000',

trace: 'on-first-retry',

screenshot: 'only-on-failure',

},

projects: [

{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },

{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },

{ name: 'mobile', use: { ...devices['iPhone 13'] } },

],

});

BrowserAct

Let your agent run on any real-world website

Bypass CAPTCHA & anti-bot for free. Start local, scale to cloud.

Explore BrowserAct Skills →

Stop writing automation&scrapers

Install the CLI. Run your first Skill in 30 seconds. Scale when you're ready.

Start free
free · no credit card