【问题标题】:selenium testing in cakephp with phpunit使用 phpunit 在 cakephp 中进行硒测试
【发布时间】: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


【解决方案1】:

在@ndm 的大力帮助下,我想出了一种在我的应用程序中将 selenium 与 phpunit 集成的方法,步骤如下:

按照此处的简单安装步骤 - Testing with Selenium WebDriver + PHPUnit

*确保您的新 ui-tests 与单元测试不在同一个文件夹中,我的在同一个文件夹中并且不断出现致命错误。

*如果运行 ./vendor/bin/steward run staging firefox 命令返回错误,则将 firefox 更改为 chrome。如果您仍然不断收到错误(就像我一样),请安装 chromedriver 并再次运行。它应该工作。

所有的努力都值得。

【讨论】:

  • 还有一件事,如果你想在 php 框架中设置它,那么你应该在你的项目中创建一个新的单独文件夹(如安装手册中所述),并初始化一个新的作曲家那里而不是使用框架的现有 phpunit。否则 selenium 将与常规 phpunit 测试发生冲突,并会继续退出并出现致命错误
猜你喜欢
  • 2014-12-25
  • 2011-10-10
  • 2016-11-07
  • 2010-10-19
  • 2016-06-04
  • 2014-02-12
  • 2020-05-16
  • 1970-01-01
  • 2011-08-25
相关资源
最近更新 更多