【发布时间】: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