playwright是微软推出的端到端的web测试工具,本文对其进行初步探索。

所依据的文档:https://playwright.dev/docs/intro。 默认以yarn作为文档管理工具。

安装试用

在一个空目录中执行yarn create playwright可以创建playwright的工程。 过程中会下载chroimum, firefox, webkit等浏览器实体。

然后就可以执行yarn playwright test来运行测试了。会同时在chromium, firefox, 以及webkit上执行测试。 若要在单浏览器实体中执行测试,则要指定之,例如:yarn playwright test --project=chromium。 错误报告则会在http://127.0.0.1:9323显示。

其配置文件为playwright.config.ts|js。可以在其中配置只在chromium运行,只须在config.projects路径下删去firefox、webkit等工程。

默认的测试用例访问的是https://playwright.dev/',总是容易失败,不知道为啥。

执行下面命令可以安装所需的浏览器实体以及对应的料包:

npx playwright install
npx playwright install-deps

在Ubuntu上浏览器实体被放置到.cache/ms-playwright下。上面的命令可以简化成npx playwright install --with-deps。如果只想安装某个浏览器实体,可以指定名字,比如chromium。

VSCode集成

默认的扩展叫做Playwright Test for VS Code。

(未完待续)