我已經在Ubuntu 16.04上安裝了selenium 3.01,chromedriver 2.27和chrome 59。跳過了所有使用chromedriver的phpunit測試
一切工作在我的本地機器上(運行gnome桌面),但不在測試機器上(沒有任何GUI)。
我開始與下一個命令的硒(我沒有這臺機器上的GUI):
[email protected]:~# telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
f
HTTP/1.1 400 No URI
Content-Length: 0
Connection: close
Server: Jetty(9.2.15.v20160210)
Connection closed by foreign host.
:
xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar -debug
我與它開始於4444端口遠程登錄檢查但是當用phpunit運行測試時,它們會失敗:
[email protected]:/var/www/dev.xxx.tt-laravel/site# "vendor/phpunit/phpunit/phpunit" tests/General/NotAuth.php --verbose
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.18-0ubuntu0.16.04.1
Configuration: /var/www/dev.domain-laravel/site/phpunit.xml
SS 2/2 (100%)
Time: 2 minutes, Memory: 12.00MB
There were 2 skipped tests:
1) NotAuth::test_shops_index_load
The Selenium Server is not active on host localhost at port 4444.
/var/www/dev.domain-laravel/site/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:299
/var/www/dev.domain-laravel/site/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:337
/var/www/dev.domain-laravel/site/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:314
2) NotAuth::test_shops_categories_load
The Selenium Server is not active on host localhost at port 4444.
/var/www/dev.domain-laravel/site/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:299
/var/www/dev.domain-laravel/site/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:337
/var/www/dev.domain-laravel/site/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:314
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Skipped: 2.
和硒標籤的輸出:
2017-07-02 17:18:00.738:INFO::main: Logging initialized @497ms
2017-07-02 17:18:00.870:INFO:osjs.Server:main: jetty-9.2.15.v20160210
2017-07-02 17:18:00.917:INFO:osjsh.ContextHandler:main: Started [email protected]8b42f{/,null,AVAILABLE}
2017-07-02 17:18:00.938:INFO:osjs.ServerConnector:main: Started [email protected]{HTTP/1.1}{0.0.0.0:4444}
2017-07-02 17:18:00.939:INFO:osjs.Server:main: Started @698ms
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 6589
Only local connections are allowed.
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 16531
Only local connections are allowed.
任何幫助表示讚賞。謝謝!
PS:這是一個測試:
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Modelizer\Selenium\SeleniumTestCase;
// https://github.com/Modelizer/Laravel-Selenium
// https://github.com/Modelizer/Laravel-Selenium/wiki/APIs
require_once(__DIR__.'/../../vendor/hacks/load_env.php');
class NotAuth extends SeleniumTestCase
{
/**
* SHOPS MODULES START
*/
public function test_shops_index_load()
{
$url = trim(route('shops_index', [], FALSE));
$this->visit($url)
->see('Top Shops')
->see('Help Center3')
->seePageIs($url)
;
}
public function test_shops_categories_load()
{
$url = trim(route('shops_categories', [], FALSE));
$this->visit($url)
->see('Automotive')
->see('Baby')
->seePageIs($url)
;
}
/**
* SHOPS MODULES END
*/
}
你可以告訴我你的連接代碼,你確定它會在沒有GUI的情況下工作嗎?硒如何打開瀏覽器? – Dennis
@丹尼斯我正在使用https://github.com/Modelizer/Laravel-Selenium,我會編輯我的問題,並把我寫的兩個測試之一 –
嘗試添加$ this-> setPort(4444);在SeleniumTestCase.php'setUp'方法內部強制端口4444。 – Dennis