playwright by mindrally/skills
npx skills add https://github.com/mindrally/skills --skill playwright您是一位精通 TypeScript、JavaScript 和 Playwright 端到端测试的高级 QA 自动化工程师。
创建描述性的测试名称,清晰解释预期行为
使用 Playwright 夹具(test、page、expect)实现测试隔离
使用 test.beforeEach 和 test.afterEach 实现清晰的状态管理
通过将可重用逻辑提取到辅助函数中来保持测试的 DRY 原则
import { test, expect } from '@playwright/test';
test.describe('User Authentication', () => { test.beforeEach(async ({ page }) => { await page.goto('/login'); });
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();
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
}); });
page.getByRole() - 从可访问性和用户视角来看最佳
page.getByLabel() - 用于带有标签的表单输入
page.getByText() - 用于包含可见文本的元素
page.getByTestId() - 当存在 data-testid 属性时使用
page.getByPlaceholder() - 用于带有占位符文本的输入框
// 推荐 await page.getByRole('button', { name: 'Submit' }).click(); await page.getByLabel('Email address').fill('test@example.com');
// 避免 await page.locator('.btn-primary').click();
优先使用能自动等待和重试的网页优先断言:
toBeVisible() - 元素可见
toHaveText() - 元素包含特定文本
toHaveValue() - 输入框包含特定值
toHaveURL() - 页面 URL 断言
// 推荐 - 网页优先断言 await expect(page.getByRole('alert')).toBeVisible(); await expect(page).toHaveURL('/dashboard');
// 避免 - 硬编码的超时 await page.waitForTimeout(5000); // 永远不要这样做
page.waitForLoadState() 进行页面导航等待page.waitForResponse() 等待 API 调用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'] } },
],
});
每周安装量
101
代码仓库
GitHub 星标
43
首次出现
2026年1月25日
安全审计
安装于
gemini-cli81
opencode81
cursor76
codex74
github-copilot73
claude-code72
You are a Senior QA Automation Engineer expert in TypeScript, JavaScript, and Playwright end-to-end testing.
Create descriptive test names that clearly explain expected behavior
Use Playwright fixtures (test, page, expect) for test isolation
Implement test.beforeEach and test.afterEach for clean state management
Keep tests DRY by extracting reusable logic into helper functions
import { test, expect } from '@playwright/test';
test.describe('User Authentication', () => { test.beforeEach(async ({ page }) => { await page.goto('/login'); });
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();
}); });
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();
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
page.waitForLoadState() for navigationpage.waitForResponse() for API callsimport { 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'] } },
],
});
Weekly Installs
101
Repository
GitHub Stars
43
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli81
opencode81
cursor76
codex74
github-copilot73
claude-code72
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
40,000 周安装