【问题标题】:Fatal error: Class 'PHPUnit_Extensions_Selenium2TestCase' not found in *.php致命错误:在 *.php 中找不到类 'PHPUnit_Extensions_Selenium2TestCase'
【发布时间】:2016-01-29 04:51:31
【问题描述】:

我对 Seleniu 完全陌生,我正在尝试使用 Selenium 2 设置 PHPUnit,遵循本教程 https://www.youtube.com/watch?v=zva_GETXimI

到目前为止,这是我所做的:

按照此处的说明使用 PHAR 安装 PHPUnit https://phpunit.de/manual/current/en/installation.html

已安装 Selenium 服务器

升级到 PHP5.6(但我的 Apache 还是 2.22 而不是 2.4)

使用 Composer 安装 PHPUnit_selenium 包

创建了一个 testLogin.php 文件:

<?php

class testLogin extends PHPUnit_Extensions_Selenium2TestCase{

    public function setUp()


    {
        $this->setHost('localhost');
        $this->setPort(4444);
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://localhost/Achievers');
    }

}

当我使用“phpunit testLogin.php”运行 testLogin.php 时出现错误:

在第 5 行的 /home/osadmin/projects/Sel/testLogin.php 中找不到类“PHPUnit_Extensions_Selenium2TestCase”

由于我刚刚开始,我不知道如何解决这个问题。在谷歌搜索错误时,它显示将此行添加到我的 php 文件中:

require_once('PHPUnit/Extensions/Selenium2TestCase.php');

但我不确定如何使用它,因为没有 PHPUnit 文件夹,只有一个链接到 PHAR 的文件。

有人可以解释一下如何解决这个问题吗?

谢谢。

编辑:

按照 Ushakov 的建议,我尝试了/path/to/phpunit.phar testLogin.php

但它给出了同样的错误。

如果我将此行添加到 testLogin.php:require_once('/usr/local/bin/phpunit');

然后运行/path/to/phpunit.phar testLogin.php

我明白了:

#!/usr/bin/env php
PHP Notice:  Constant __PHPUNIT_PHAR__ already defined in /usr/local/bin/phpunit on line 18
PHP Notice:  Constant __PHPUNIT_PHAR_ROOT__ already defined in /usr/local/bin/phpunit on line 19
PHP Fatal error:  Cannot redeclare class DeepCopy\DeepCopy in phar:///usr/local/bin/phpunit/myclabs-deep-copy/DeepCopy/DeepCopy.php on line 15

【问题讨论】:

  • 你试过运行/path/to/phpunit.phar testLogin.php吗?
  • 试过了,同样的错误。在原始问题中发布了一些编辑

标签: selenium selenium-webdriver phpunit


【解决方案1】:

通过将这一行添加到 PHP 文件中来解决它:

require_once 'vendor/autoload.php';

我见过的教程没有提到这一点,但可以在 github 项目中找到它

【讨论】:

  • 是的,它没有解决问题。显示此错误:Declaration of PHPUnit_Extensions_Selenium2TestCase::run(?PHPUnit\Framework\TestResult $result = NULL) must be compatible with PHPUnit\Framework\Test::run(?PHPUnit\Framework\TestResult $result = NULL): PHPUnit\Framework\TestResult in /Applications/MAMP/htdocs/selenium/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php on line 596
  • 这个答案并没有为我解决它..
【解决方案2】:

对于迟到聚会的其他人 - 这对我有用:

class testLogin extends \PHPUnit\Extensions\Selenium2TestCase

(使用 PHP 7.0.3 并使用 Composer 安装 Selenium 包)。

【讨论】:

    猜你喜欢
    • 2015-03-20
    • 2016-05-11
    • 2013-11-03
    • 2016-09-17
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2013-09-27
    相关资源
    最近更新 更多