peridot-php / webdriver-manager
Selenium WebDriver 管理的库和命令行工具
Requires
- php: >=5.4.0
- evenement/evenement: ~2.0
- splitbrain/php-archive: ~1.0
- symfony/console: ~2.6
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-20 22:12:44 UTC
README
功能测试项目的完美伴侣。深受protractor 中的 webdriver-manager
启发。WebDriver Manager 允许您保持 Selenium Server 二进制文件更新。它还提供了一种打包解决方案,可轻松启动 Selenium Server。
除了易于使用的命令行应用程序外,WebDriver Manager 还提供了一种库,用于在您的应用程序和工具中管理 Selenium 二进制文件。
安装
WebDriver Manager 旨在成为任何使用 Selenium WebDriver 进行功能测试的项目的一个即插即用的安装。
$ composer require --dev peridot-php/webdriver-manager
安装后,您可以从项目的舒适环境中操作 Selenium Server
$ vendor/bin/manager start
使用方法
clean
删除所有已安装的二进制文件。
status
列出所有可用的二进制文件及其安装状态。状态显示二进制文件是否已安装、过时或缺失。
update
更新命令会下载当前的二进制文件并删除旧的二进制文件。
start
启动由 WebDriver Manager 管理的所有驱动程序的可选 Selenium Server。start 命令将在启动时运行更新,以确保驱动程序可用且最新。
库使用
WebDriver manager 提供了一个非常简单的接口,使其很容易在您的应用程序和工具中利用。
use Peridot\WebDriverManager\Manager; $manager = new Manager(); $manager->update(); //update all binaries $manager->update('selenium'); //only update selenium $manager->clean(); //remove installed binaries $manager->startInForeground(); //start selenium in the foreground on port 4444 $manager->startInForeground(9999); //start selenium in the foreground on port 9999 $manager->startInBackground(); //start selenium in the background on port 4444 $manager->startInBackground(9999); //start in the background on port 9999 $path = $manager->getInstallPath(); //where binaries are installed $manager->setInstallPath(__DIR__); //set the path to install binaries $manager->addBinary(new MyCustomDriver()); //add a binary to manage $manager->removeBinary('chromdedriver'); //remove a managed binary $binaries = $manager->getBinaries(); //get a collection of managed binaries
关于在后台启动 Selenium 的说明
WebDriver Manager 在启动后台进程时不会阻塞。这使得很难看到 Selenium 是否遇到任何错误(可能是损坏的二进制文件?)。SeleniumProcess
类提供了一个用于检查进程状态的方法。如果您想检查在后台启动的 Selenium Server 是否正常,可以尝试以下操作
$process = $manager->startInBackground(); usleep(250000); //give Selenium a quarter of a second to validate input if (! $process->isRunning()) { //Selenium encountered an error print $process->getError(); $process->close(); return; } //do rad Selenium things
有关更多信息,请参阅 API 文档;
示例
该 API 已用于创建一个 自定义 Behat 监听器,该监听器可以在运行 Mink 测试之前启动服务器。此工具作为名为 行为驱动待办事项 的演示项目的部分。
运行测试
WebDriver Manager 的测试使用 Peridot 测试框架编写。
单元测试可以像这样运行
$ vendor/bin/peridot
集成测试可以像这样运行
$ vendor/bin/peridot --grep *.it.php
贡献
请随时提交问题或拉取请求。