2017-07-02 73 views
0

我已經在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 
    */ 
} 
+0

你可以告訴我你的連接代碼,你確定它會在沒有GUI的情況下工作嗎?硒如何打開瀏覽器? – Dennis

+0

@丹尼斯我正在使用https://github.com/Modelizer/Laravel-Selenium,我會編輯我的問題,並把我寫的兩個測試之一 –

+0

嘗試添加$ this-> setPort(4444);在SeleniumTestCase.php'setUp'方法內部強制端口4444。 – Dennis

回答

0

我一直有完全相同的問題,在過去兩年多月,一直在做一噸圍繞本次調查的。

我發現我的環境,當地的全過程工作,但未能生成服務器上完全相同的設置...

最後我注意到,當地的,我正在運行和安裝一切爲用戶流浪漢。然而,在構建服務器(Ubuntu 16.04.2 LTS)上,我以root身份執行了所有操作,並且手動向PATH添加項目是不可能的,因爲系統由Puppet維護。

注意到,我將所有必需的權限更改爲Jenkins(ci將最終運行測試)。

我還全球安裝了phpunit & phpunit-selenium以及所有必需工具的特定版本。

  • 的Xvfb
  • 谷歌鉻 - V59.0.3071.115
  • 火狐 - V54.0
  • Chromedriver - V2.30
  • GeckoDriver - V0.16.1
  • 硒獨立服務器 - V3.4.0
  • PHPUnit - V5.7.21
  • PHPUit-Selenium - V3.0。3

安裝我也跟着: 的Java:

apt-get -qq install default-jre 

谷歌鉻:

apt-get -qq install libxss1 libappindicator1 libindicator7 
wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_59.0.3071.115-1_amd64.deb 
dpkg -i google-chrome*.deb 
apt-get -qq install -f 

火狐:

apt-get -qq update 
apt-get -qq install firefox 

的Xvfb:

apt-get -qq install xvfb 

Google Chrome驅動程序。 (V2.30):

cd ~/ 
mkdir browser-drivers 
cd browser-drivers 
wget https://chromedriver.storage.googleapis.com/2.30/chromedriver_linux64.zip 
unzip chromedriver*.zip 
chmod a+x chromedriver 
chmod 775 chromedriver 
chown jenkins:jenkins chromedriver 

Firefox Gecko驅動程序。 (V0.16.1):

cd ~/browser-drivers 
wget -N https://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-linux64.tar.gz 
tar -xvzf geckodriver* 
chmod a+x geckodriver 
chmod 775 geckodriver 
chown jenkins:jenkins geckodriver 

硒獨立:

cd ~/ 
mkdir selenium 
cd selenium 
wget -N http://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar 
chmod a+x selenium* 
chown jenkins:jenkins selenium* 

PHPUnit的(V5.7.21):

curl -Lo /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-5.7.21.phar 
chmod +x /usr/local/bin/phpunit 
chown -R jenkins:jenkins /usr/local/bin/phpunit 
# Run from "/var/lib/jenkins" as jenkins user 
cd /var/lib/jenkins 
su jenkins 
composer global require 'phpunit/phpunit=5.*' 
composer global require 'phpunit/phpunit-selenium=3.0.3' 

然後我還創建了兩個腳本來啓動這兩個xvfb的&硒在每次測試努力之後。以這種方式

seleniumxvfbup.sh

#!/bin/bash 

Xvfb :8 -screen 8 1920x1080x24 -ac +extension GLX +render -noreset > /dev/null 2>&1 & 

export DISPLAY=:8.8 

java -Dwebdriver.gecko.driver=browser-drivers/geckodriver -Dchrome.binary=/opt/google/chrome/chrome -Dwebdriver.chrome.driver=browser-drivers/chromedriver -jar selenium/selenium-server-standalone-3.4.0.jar -port 4444 > /dev/null 2>&1 & 

啓動硒服務器允許我對無論是Chrome或Firefox單獨的測試,而無需停止/每次啓動硒。

查殺服務很簡單,只要

pkill -f selenium & pkill -f Xvfb & 

最後

chmod +x ~/seleniumxvfbup.sh 
chown jenkins:jenkins seleniumxvfbup.sh 

只要確保沒有所需的文件駐留在/ root /目錄,因爲這是主要問題系統失敗了。

希望這可以幫助你...