简体   繁体   English

phpunit selenium2重复测试不起作用

[英]phpunit selenium2 repeat test not working

I am trying to run phpunit with selenium2 for testing my php code. 我正在尝试使用selenium2运行phpunit来测试我的php代码。

php version : 5.6
laravel version : 5.2
phpunit vesrion : PHPUnit 3.7.28 by Sebastian Bergmann.

Initial command to start selenium server : 启动硒服务器的初始命令:

java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar ~/Downloads/selenium-server-standalone-3.4.0.jar

Mytest.php 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);
}
}

When i run the above code via command line using following command : 当我使用以下命令通过命令行运行以上代码时:

vendor/bin/phpunit --filter testcheckhere --verbose --repeat 2 --log-junit textexe.xml tests/selenium/MyTest.php 

I get following error : 我收到以下错误:

    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.

Also while test is running , chrome browser opens only once during the first test and later on it doesn't try to open it again. 同样,在测试运行时,Chrome浏览器在第一个测试期间只会打开一次,以后不会尝试再次打开它。

php version : 5.6 laravel version : 5.2 phpunit vesrion : PHPUnit 3.7.28 by Sebastian Bergmann. php版本:5.6 laravel版本:5.2 phpunit vesrion:Sebastian Bergmann编写的PHPUnit 3.7.28。

Update your PHPUnit version in Xampp folder like: 在Xampp文件夹中更新您的PHPUnit版本,如下所示:

1- Download the last version of PHPUnit here: https://phpunit.de/index.html 2- Copy “phpunit.phar” in “C:\\xampp\\php”. 1-在此处下载最新版本的PHPUnit: https ://phpunit.de/index.html 2-在“ C:\\ xampp \\ php”中复制“ phpunit.phar”。 3- In the file: “phpunit.bat.bat”, update the following line: "%PHPBIN%" "C:\\xampp\\php\\phpunit" %* to : "%PHPBIN%" "C:\\xampp\\php\\phpunit.phar" %* 3-在文件:“ phpunit.bat.bat”中,将以下行更新:“%PHPBIN%”“ C:\\ xampp \\ php \\ phpunit”%*至:“%PHPBIN%”“ C:\\ xampp \\ php \\ phpunit.phar“%*

You have version compatibility issue, once your php version and phpunit version will be compatible with eachother then your application will run without issue. 您有版本兼容性问题,一旦您的php版本和phpunit版本彼此兼容,则您的应用程序将正常运行。 Download the phpunit.phar file version 5.7.26 because it will be compatible with your PHP Version 下载phpunit.phar文件版本5.7.26,因为它将与您的PHP版本兼容

Also remove your function: 同时删除您的功能:

public function tearDown() { $this->stop(); 公共功能tearDown(){$ this-> stop();

//parent::tearDown();

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM