codeception / module-playwright
Codeception的Playwright模块
Requires
- codeception/codeception: ^5.0
- symfony/process: ^6 || ^7
This package is auto-updated.
Last update: 2024-09-19 23:10:53 UTC
README
🚀 这是第一个也是唯一一个允许在PHP中进行Playwright测试的模块。Playwright 允许在Chrome、Firefox、Webkit(safari)中进行测试。它是Selenium WebDriver的更快、更可靠的替代品。最后,它也适用于PHP!
此模块不直接在PHP中实现Playwright API,而是通过代理请求到CodeceptJS的Playwright助手。这是因为Codeception和CodeceptJS遵循相同的架构原则,并且Web测试的接口非常相似。
注意
此模块可以用作WebDriver模块的替代品。与WebDriver模块相比,Playwright模块可以将测试速度提高3倍,支持无头模式,可以自动记录视频和堆栈跟踪。
要求
- PHP 8.1+
- NodeJS 20+
安装
警告
此模块是实验性的。它处于早期开发阶段。请报告您发现的所有问题。
安装此模块的NodeJS部分,它将安装Playwright和CodeceptJS
npm install codeception-module-playwright
安装Playwright浏览器
npx playwright install --with-deps
安装此模块的PHP部分
composer require codeception/module-playwright --dev
配置
在codeception.yml
中启用模块
modules: enabled: - Playwright: url: 'http://localhost' browser: 'chromium' show: true
最常见的配置值如下
url
- 用于打开页面的基本URLbrowser
-chromium
、firefox
或webkit
show
- (默认:true
) 显示浏览器或设置为false
以在无头模式下运行测试timeout
- (默认:5000
) 所有Playwright操作的超时时间(毫秒)pw_start
- (默认:true
) 自动启动Playwright服务器(CodeceptJS代理)。如果服务器无法启动,请将其设置为false
并手动启动服务器。pw_server
- (默认: 'http://localhost:8191') Playwright服务器的URLpw_debug
- (默认:false
) 打印Playwright服务器调试信息video
- 失败时保存视频trace
- 失败时保存跟踪信息
更多配置选项请参阅CodeceptJS Playwright页面
提示
此模块设计为即插即用的WebDriver模块替代品,您可以在测试中将WebDriver
更改为Playwright
并尝试它的工作方式!
用法
Playwright模块需要运行NodeJS服务器。Playwright模块将启动它并自动停止。默认端口是8191。
如果您想禁用自动服务器启动,请将start
选项设置为false
modules: enabled: - Playwright: url: 'http://localhost' browser: 'chromium' show: true pw_start: false
在这种情况下,您可以手动启动服务器
npx codeception-playwright-module
请确保服务器可以无问题启动。
如果您在不同的主机或端口上启动服务器,您可以进行配置
modules: enabled: - Playwright: url: 'http://localhost' browser: 'chromium' show: true pw_start: false pw_server: http://otherhost:8191
API
此模块提供与WebDriver模块相同的API。您可以在测试中使用它而无需任何更改。
有关完整命令列表,请参阅WebDriver模块参考。
Playwright特定的命令也可在CodeceptJS Playwright Helper中找到
示例
$I->amOnPage('/'); $I->click('#first .clickable'); $I->dontSeeInTitle('Error'); $I->see('Hello, world!');