【发布时间】:2017-12-05 22:04:05
【问题描述】:
我在 Ubuntu 16.04 上安装了 selenium 3.01、chromedriver 2.27 和 chrome 59。
一切都可以在我的本地机器上运行(运行 gnome 桌面),但不能在测试机器上运行(没有任何 GUI)。
我使用下一个命令启动了 Selenium(我在这台机器上没有 GUI):
xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar -debug
我用 telnet 确认它从 4444 端口开始:
root@xxx:~# 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.
但是当使用 phpunit 运行测试时,它们会失败:
root@xxx:/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.
以及 selenium 选项卡的输出:
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 o.s.j.s.ServletContextHandler@5158b42f{/,null,AVAILABLE}
2017-07-02 17:18:00.938:INFO:osjs.ServerConnector:main: Started ServerConnector@6771beb3{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 的情况下工作吗? selenium 将如何打开浏览器?
-
@Dennis 我正在使用github.com/Modelizer/Laravel-Selenium,我将编辑我的问题并放入我编写的 2 个测试之一
-
尝试添加 $this->setPort(4444);在 SeleniumTestCase.php 'setUp' 方法中强制使用端口 4444。
-
我忘了说一切都在我的电脑上运行(使用 gnome)。
-
stackoverflow.com/questions/34342632/… 也许它会帮助你。你试过 setPort(4444) 吗?
标签: selenium selenium-webdriver laravel-5 phpunit ubuntu-16.04