【发布时间】:2017-08-14 17:16:57
【问题描述】:
我想了解在 phpunit 中使用 selenium 进行 ui 测试。我在我的 cakephp 项目上安装了 phpunit,它运行良好。然后我决定按照https://phpunit.de/manual/3.7/en/selenium.html 中描述的步骤安装selenium(我使用以下命令$ php composer.phar require --dev phpunit/phpunit-selenium: ">=1.2" 在我的项目中安装了selenium。现在使用它的jar 文件启动selenium 服务器后,我一直在尝试运行提供的示例测试在上面的链接中,但我收到以下错误:
$ 供应商/bin/phpunit
PHP 致命错误:类 'PHPUnit_Framework_TestCase' 未在 /var/www/html/ujols/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php 在第 97 行
似乎错误与作曲家一起安装的 Selenium2TestCase.php 文件有关。这就是 Selenium2TestCase.php 文件的开始方式:
abstract class PHPUnit_Extensions_Selenium2TestCase extends PHPUnit_Framework_TestCase
{
这里有没有人设法在 cakephp 或任何其他 php 框架上安装 selenium?如果您能帮我解决问题,我将不胜感激
编辑我一直试图运行的示例测试用例以检查 selenium 是否正常工作:
PlainviewTest.php
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->url('http://www.example.com/');
$this->assertEquals('Example WWW Page', $this->title());
}
}
?>
【问题讨论】:
-
注意到我在安装版本 6 时实际上正在查看 phpunit 3.7 手册... 有人有 phpunit6 中 selenium 安装手册的链接吗?
-
我认为没有,因为它还不兼容。 github.com/giorgiosironi/phpunit-selenium/pull/404
-
@ndm 感谢您的评论! facebook 的 php-webdriver 怎么样? github.com/facebook/php-webdriver我尝试实现它,但我不知道如何运行测试
-
查看文档Testing framework integration 部分,除了通过 Steward 进行更复杂的集成之外,还有一些非常基本的手动 PHPUnit 集成示例。 webdriver 库本身没有“测试功能”,它只是与 Selenium 的连接,您可以在任何您想要的 PHP 脚本中使用它。
-
@ndm 非常感谢您的分享!!!!我已经安装了它,我正在尝试运行他们的示例测试断言 w3.org 标题,但是当我运行测试时它说`[ERROR] Testcases executed: 1 (fatal: 1)`,日志文件是空的.. 这里是我的文件gist.github.com/nodirashidov/176a76d46031fe6f4063f6fb0834d838
标签: php selenium cakephp phpunit