Skip to content

Playwright

一句话解释

Playwright 是 modern E2E 测试 tool 通过 Microsoft — 快, reliable, cross-浏览器, 使用 auto-waiting 构建 in.

用大白话说

Playwright 是 modern 端-到-端测试框架创建通过 Microsoft. 它's become very popular 因为它 解决许多 pain 点的 older E2E tools.

Key features:

  • Cross-browser: 测试运行 on Chromium, Firefox, and WebKit (Safari)
  • Auto-waiting: automatically waits for 元素到 是 ready, reducing flaky 测试
  • Fast: 运行测试 in parallel 跨越浏览器
  • Multi-language: supports JavaScript, TypeScript, Python, Java, C#
  • Network interception: 能 mock and monitor network 请求
  • Trace viewer: powerful 调试 tool for 失败测试

Playwright 是经常 compared 到 Cypress. Playwright's advantages 包含 multi-浏览器 support, multi-tab 测试, and 否 paid features. Cypress 有 nicer developer experience for 初学者 and 时间-travel 调试.

示例

javascript
// login.spec.js — Playwright E2E test
import { test, expect } from '@playwright/test';

test('user can log in', async ({ page }) => {
  await page.goto('https://app.example.com/login');

  await page.fill('#username', 'alice');
  await page.fill('#password', 'secret123');
  await page.click('button[type="submit"]');

  await expect(page).toHaveURL(/dashboard/);
  await expect(page.locator('h1')).toHaveText('Welcome, Alice');
});

// Run: npx playwright test
//  Running 1 test using 1 worker
//  ✓ login.spec.js:3 › user can log in (1.2s)
//  1 passed

Playwright 驱动真实浏览器:导航到 URL、填写输入、点击按钮、断言结果 URL 和页面内容——就像真实用户操作一样。

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表