Skip to content

Commit

Permalink
Dev: Try Firefox headless instead of chromedriver on Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Nov 24, 2017
1 parent a8cb363 commit be79139
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Expand Up @@ -52,8 +52,16 @@ before_script:
- more localhost

# Chromedriver setup.
- wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
# Note: Keep getting timeout problems on Travis with chromedriver.
#- wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
#- unzip chromedriver_linux64.zip

# Setup Selenium with Firefox headless mode.
- wget "https://selenium-release.storage.googleapis.com/3.7/selenium-server-standalone-3.7.1.jar"
- wget "https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-arm7hf.tar.gz"
- tar xvzf geckodriver-v0.19.1-arm7hf.tar.gz
- export MOZ_HEADLESS=1
- java -jar selenium-server-standalone-3.7.1.jar -enablePassThrough false > /dev/null &

script:
- DOMAIN=localhost phpunit
27 changes: 20 additions & 7 deletions tests/TestBaseClassWeb.php
Expand Up @@ -21,6 +21,9 @@
use Facebook\WebDriver\Exception\TimeOutException;
use Facebook\WebDriver\Chrome\ChromeDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Firefox\FirefoxProfile;
use Facebook\WebDriver\Firefox\FirefoxPreferences;

/**
* Class TestBaseClassWeb
Expand Down Expand Up @@ -60,18 +63,28 @@ public static function setUpBeforeClass()

$base = \Yii::app()->getBasePath();

/*
$caps = new DesiredCapabilities();
$chromeOptions = new ChromeOptions();
$chromeOptions = new FirefoxProfile();
$noHeadless = getenv('NOHEADLESS');
if (empty($noHeadless)) {
$chromeOptions->addArguments(['--headless', 'window-size=1400,1024']);
//$chromeOptions->addArguments(['--headless', 'window-size=1400,1024']);
} else {
$chromeOptions->addArguments(['window-size=1400,1024']);
//$chromeOptions->addArguments(['window-size=1400,1024']);
}
$caps->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);

putenv(sprintf('webdriver.chrome.driver=/%s/../chromedriver', $base));
self::$webDriver = ChromeDriver::start($caps);
$caps->setCapability($chromeOptions);
putenv(sprintf('webdriver.firefox.driver=/%s/../firefoxdriver', $base));
self::$webDriver = FirefoxDriver::start($caps);
*/

$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::firefox();
$profile = new FirefoxProfile();
$profile->setPreference(FirefoxPreferences::READER_PARSE_ON_LOAD_ENABLED, false);
$profile->setPreference('browser.link.open_newwindow', 3);
$capabilities->setCapability(FirefoxDriver::PROFILE, $profile);
self::$webDriver = RemoteWebDriver::create($host, $capabilities, 5000);

// Implicit timout so we don't have to wait manually.
self::$webDriver->manage()->timeouts()->implicitlyWait(5);
Expand Down
2 changes: 2 additions & 0 deletions tests/controllers/CreateSurveyTest.php
Expand Up @@ -231,6 +231,8 @@ public function testCreateSurvey()
);
$execute->click();

sleep(1);

// Switch to new tab.
$windowHandles = self::$webDriver->getWindowHandles();
self::$webDriver->switchTo()->window(
Expand Down
12 changes: 9 additions & 3 deletions tests/data/travis/travis_setup.sh
Expand Up @@ -33,7 +33,13 @@ sudo cp -f tests/travis/travis-ci-apache /etc/apache2/sites-available/000-defaul
sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf
sudo service apache2 restart

wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
# Chromedriver does not work on Travis.
#wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
#unzip chromedriver_linux64.zip

# TODO: For firefox, export MOZ_HEADLESS=1, install selenium.
# Firefox headless.
wget "https://selenium-release.storage.googleapis.com/3.7/selenium-server-standalone-3.7.1.jar"
wget "https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-arm7hf.tar.gz"
tar xvzf geckodriver-v0.19.1-arm7hf.tar.gz
export MOZ_HEADLESS=1
java -jar selenium-server-standalone-3.7.1.jar -enablePassThrough false > /dev/null &

0 comments on commit be79139

Please sign in to comment.