【发布时间】:2018-05-12 19:49:12
【问题描述】:
我正在尝试使用 selenium2 运行 phpunit 来测试我的 php 代码。
php version : 5.6
laravel version : 5.2
phpunit vesrion : PHPUnit 3.7.28 by Sebastian Bergmann.
启动 selenium 服务器的初始命令:
java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar ~/Downloads/selenium-server-standalone-3.4.0.jar
Mytest.php
class Mytest extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp() {
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowserUrl('http://www.example.com');
$this->setBrowser('chrome'); // firefox
//parent::setUp();
}
public function tearDown() {
$this->stop();
//parent::tearDown();
}
public function testcheckhere(){
$this->url("http://www.google.com");
sleep(5);
}
}
当我使用以下命令通过命令行运行上述代码时:
vendor/bin/phpunit --filter testcheckhere --verbose --repeat 2 --log-junit textexe.xml tests/selenium/MyTest.php
我收到以下错误:
PHPUnit 5.7.9 by Sebastian Bergmann and contributors.
Runtime: PHP 5.6.31-2+ubuntu14.04.1+deb.sury.org+1
Configuration: /var/www/html/CRM/phpunit.xml
.E 2 / 2 (100%)
Time: 9.04 seconds, Memory: 6.25MB
There was 1 error:
1) Mytest::testcheckhere
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'lp-0500', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-43-generic', java.version: '1.8.0_151'
Driver info: driver.version: unknown
/var/www/html/mycode/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Driver.php:165
/var/www/html/mycode/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Driver.php:175
/var/www/html/mycode/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/CommandsHolder.php:100
/var/www/html/mycode/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:394
/var/www/html/mycode/tests/selenium/MyTest.php:29
/var/www/html/mycode/tests/selenium/MyTest.php:29
/var/www/html/mycode/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:348
/var/www/html/mycode/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:314
ERRORS!
Tests: 2, Assertions: 0, Errors: 1.
此外,在测试运行时,chrome 浏览器在第一次测试期间仅打开一次,之后不再尝试再次打开。
【问题讨论】:
-
看来 selenium 服务器不知道在哪里可以找到 webdriver。
-
如果你将 chromedriver 二进制文件和 selenium server jar 放在同一个目录下,你不必指定 Dwebdriver.chrome.driver 参数。也可以尝试
$this->setBrowser('*chrome')与 asterix 并在 setUp 方法中设置您的测试基础 URL$this->setBrowserUrl然后在测试中只需调用$this->url('/');phpunit 将自动调用所有以 test 所以 --filter 参数是不必要的。这些是我的建议,但我在这件事上是新手。祝你好运。
标签: selenium selenium-webdriver phpunit laravel-5.2 selenium-chromedriver