Sorin Trimbitas
Sorin Trimbitas

Reputation: 1497

Skipped all tests on phpunit with chromedriver

I have installed selenium 3.01, chromedriver 2.27 and chrome 59 on an Ubuntu 16.04.

Everything works on my local machine (running gnome desktop) but not on a test machine (without any GUI).

I started the Selenium with the next command (I don't have a GUI on this machine):

xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar -debug

I checked with telnet that it starts on port 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.

But when running the tests with phpunit they fail:

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.

and the output from the selenium tab:

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.

Any help is appreciated. Thank you!

PS : This is one of the tests:

<?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
     */
}

Upvotes: 0

Views: 1029

Answers (1)

Kamakazy
Kamakazy

Reputation: 109

I have been having the exact same issue the past two odd months and have been doing a ton of investigation around this.

I noticed on my environment that locally the whole process works but the exact same setup on a build server failed...

I ended up noticing that on local, I was running and installing everything as the vagrant user. On the build server however (Ubuntu 16.04.2 LTS), I did everything as root and adding items manually to the PATH was impossible as the system is maintained by Puppet.

Noticing that, I changed all the required permissions to Jenkins (ci will be running the tests eventually).

I also globally installed phpunit & phpunit-selenium along with specific versions of all the required tools.

  • Xvfb
  • Google-Chrome - V59.0.3071.115
  • FireFox - V54.0
  • Chromedriver - V2.30
  • GeckoDriver - V0.16.1
  • Selenium Standalone Server - V3.4.0
  • PHPUnit - V5.7.21
  • PHPUit-Selenium - V3.0.3

Installation I followed: Java:

apt-get -qq install default-jre

Google-Chrome:

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

Firefox:

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

Xvfb:

apt-get -qq install xvfb

Google Chrome Driver. (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 Driver. (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

Selenium Standalone:

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'

I then also created two scripts to start up both xvfb & selenium after each test effort.

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 &

Starting selenium server in this way allows me to have individual tests on either chrome or firefox without having to stop/start selenium every time.

Killing the services is as simple as

pkill -f selenium & pkill -f Xvfb &

and finally

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

Just make sure that none of the required files reside in the /root/ dir as this was the main issue in the system failing on my side.

Hope this helps you out...

Upvotes: 1

Related Questions