云图AI云图AI
P

playwright

Apache-2.0TypeScript

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

94kFork 6k更新于 2026-08-01

软件介绍

Playwright 是一个用于 Web 测试和自动化的框架,通过单一 API 驱动 Chromium、Firefox 和 WebKit。它支持端到端测试、浏览器自动化脚本、AI 代理集成,并提供测试运行器、CLI、MCP 服务器和 VS Code 扩展等多种使用方式。

核心功能

跨浏览器支持:Chromium、Firefox 和 WebKit
自动等待和 Web 优先断言
弹性定位器(如 getByRole、getByLabel)
测试隔离:每个测试使用独立的浏览器上下文
内置追踪、截图和视频录制
并行测试执行
支持无头和有头模式
网络请求拦截和模拟
移动设备模拟
支持 TypeScript 和 JavaScript

适用场景

端到端 Web 应用测试浏览器自动化脚本(如爬虫、截图、PDF 生成)AI 代理的浏览器控制(通过 MCP 或 CLI)跨浏览器兼容性测试UI 组件测试

Docker 部署

docker build -t playwright-app . && docker run --rm playwright-app

FAQ

Playwright 支持哪些浏览器?

Playwright 支持 Chromium、Firefox 和 WebKit(包括 Safari)。

Playwright 与 Puppeteer 有何不同?

Playwright 支持多浏览器(Puppeteer 仅 Chromium),并提供更丰富的功能如自动等待、网络拦截和追踪。

如何安装 Playwright?

对于测试运行器,运行 `npm init playwright@latest`;对于库,运行 `npm i playwright`。

Playwright 是否支持移动设备模拟?

是的,Playwright 内置了设备描述符(如 iPhone 15),可以模拟移动设备。