Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Switching PhantomJS to Selenium #520

Merged
merged 13 commits into from
Oct 11, 2016
16 changes: 14 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Note that the example .travis.yml file for child projects lives in /install.
sudo: true
language: php
dist: trusty

php:
- 5.6
Expand All @@ -24,7 +25,12 @@ notifications:

addons:
ssh_known_hosts:
- svn-5223.devcloud.hosting.acquia.com
- svn-5223.devcloud.hosting.acquia.com
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6

before_install:
# Decrypt private SSH key id_rsa_blt.enc, save as ~/.ssh/id_rsa_blt.
Expand All @@ -40,7 +46,7 @@ before_install:
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- git config --global user.name "Travis-CI"
- git config --global user.email "[email protected]"
- mysql -e 'CREATE DATABASE drupal;'
- mysql -u root -e 'CREATE DATABASE drupal;'

install:
# Load composer dependencies.
Expand All @@ -54,6 +60,12 @@ install:
- nvm use 4.4.1
# Initialize drupal console default configuration.
- drupal init
# Initialize xvfb (see https://docs.travis-ci.com/user/gui-and-headless-browsers)
- sudo apt-get install xvfb
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
# Installs chromedriver to vendor/bin.
- ./scripts/linux/install-chrome.sh $TRAVIS_BUILD_DIR/vendor/bin

before_script:
# Clear drush release history cache, to pick up new releases.
Expand Down
6 changes: 5 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Ensure that [Xcode](https://itunes.apple.com/us/app/xcode/id497799835?mt=12) is
Then install the minimum dependencies for BLT. The preferred method is via Homebrew, though you could install these yourself without a package manager.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git composer drush
brew install php56 git composer drush
composer global require "hirak/prestissimo:^0.3"

If you'd like to create a VM with BLT, you will require the following additional libraries. If you'd like to use a LAMP stack other than Drupal VM, see [Local Development](readme/local-development.md).
Expand All @@ -29,6 +29,10 @@ If you'd like to create a VM with BLT, you will require the following additional
brew install ansible
brew cask install virtualbox vagrant

If you'd like to execute Behat tests from the host machine, you will need Java:

brew cask install java

### Windows

Windows is currently supported only when using the [Bash on Ubuntu on Windows](https://msdn.microsoft.com/en-us/commandline/wsl/about) feature available in the latest version of Windows 10.
Expand Down
8 changes: 5 additions & 3 deletions phing/build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
behat:
config: ${repo.root}/tests/behat/local.yml
haltonerror: true
strict: true
profile: local
# If true, `drush runserver` will be used for executing tests.
run-server: false
# This is used for ad-hoc creation of a server via `drush runserver`.
server-url: http://127.0.0.1:8888
# If true, PhantomJS GhostDriver will be launched with Behat.
launch-phantom: true
# If true, Selenium standalone server will be launched with Behat.
launch-selenium: true
# An array of paths with behat tests that should be executed.
paths:
# - ${docroot}/modules
# - ${docroot}/profiles
- ${docroot}/profiles
- ${repo.root}/tests/behat
tags: '~ajax'
verbose: ${blt.verbose}
Expand Down
16 changes: 1 addition & 15 deletions phing/tasks/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,14 @@
</target>

<target name="setup:behat" description="Generates tests/behat/local.yml file for executing Behat tests locally.">
<mkdir dir="${reports.localDir}/behat"/>
<echo>Attempting to generate tests/behat/local.yml.</echo>
<copy file="${repo.root}/tests/behat/example.local.yml" tofile="${repo.root}/tests/behat/local.yml" verbose="true">
<filterchain>
<expandproperties />
</filterchain>
</copy>

<exec dir="${repo.root}" command="php -r 'require &quot;./vendor/jakoch/phantomjs-installer/src/PhantomInstaller/PhantomBinary.php&quot;; $pb = new \PhantomInstaller\PhantomBinary(); echo $pb->getBin();'" checkreturn="false" returnProperty="phantomjs.missing" outputProperty="phantomjs.bin"/>
<if>
<or>
<istrue value="${phantomjs.missing}"/>
<not><available file="${composer.bin}/phantomjs"/></not>
<not><available file="${phantomjs.bin}"/></not>
</or>
<then>
<exec dir="${repo.root}" command="composer install-phantom" checkreturn="true" logoutput="true" passthru="true" level="${blt.exec_level}"/>
</then>
<else>
<echo>Found PhantomJS at ${phantomjs.bin}</echo>
</else>
</if>

<property file="${repo.root}/tests/behat/local.yml" prefix="behatConfig"/>
<if>
<or>
Expand Down
53 changes: 36 additions & 17 deletions phing/tasks/tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

<!-- If you experience 'Maximum function nesting level' errors in your PHP
error log, set 'xdebug.max_nesting_level=1000' in php.ini. -->
<target name="tests:behat" depends="setup:behat, tests:run-server, tests:phantomjs:launch" description="Executes Behat all behat tests in behat.paths.">
<target name="tests:behat" depends="setup:behat, tests:run-server, tests:selenium:launch" description="Executes Behat all behat tests in behat.paths.">
<mkdir dir="${reports.localDir}/behat"/>
<foreach list="${behat.paths}" target="tests:behat:execute" param="behat.path"/>
<phingcall target="tests:phantomjs:kill"/>
<phingcall target="tests:selenium:kill"/>
</target>

<target name="tests:behat:execute" description="Executes behat tests against specific path." hidden="true">
Expand All @@ -32,8 +32,8 @@
config="${behat.config}"
profile="${behat.profile}"
verbose="${behat.verbose}"
strict="true"
haltonerror="false"
strict="${behat.strict}"
haltonerror="${behat.haltonerror}"
returnProperty="behatPass"
out="std,${reports.localDir}"
format="pretty,junit"
Expand All @@ -44,7 +44,7 @@
<!-- A non-zero returns status indicates failure. -->
<not><equals arg1="${behatPass}" arg2="0"/></not>
<then>
<phingcall target="tests:phantomjs:kill"/>
<phingcall target="tests:selenium:kill"/>
<fail message="One ore more Behat tests failed." />
</then>
<else>
Expand All @@ -58,30 +58,49 @@
</if>
</target>

<target name="tests:phantomjs:launch"
description="Launches a GhostDriver."
<target name="tests:selenium:launch"
description="Launches Selenium standalone server."
hidden="true">

<if>
<equals arg1="${behat.launch-phantom}" arg2="true"/>
<equals arg1="${behat.launch-selenium}" arg2="true"/>
<then>
<echo message="Launching PhantomJS GhostDriver." />
<exec command="${composer.bin}/phantomjs --webdriver=4444"
<phingcall target="tests:selenium:kill"/>
<echo message="Launching Selenium standalone server." />
<touch file="${repo.root}/reports/selenium2.log"/>
<property name="reports.selenium2" value="${reports.localDir}/selenium2.log"/>
<exec command="${composer.bin}/selenium-server-standalone -port 4444 -log ${reports.selenium2}"
dir="${repo.root}"
passthru="true"
spawn="true"
checkreturn="true"
level="${blt.exec_level}"/>
<echo message="Waiting 10 seconds for PhantomJS (http://127.0.0.1:4444) to become available."/>
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second">
<http url="http://127.0.0.1:4444"/>
level="${blt.exec_level}"
logoutput="false"/>
<echo>Selenium2 logs are being written to ${reports.selenium2}.</echo>
<echo message="Waiting 10 seconds for Selenium standalone server (http://127.0.0.1:4444) to become available."/>
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second" timeoutproperty="selenium.timedout">
<http url="http://127.0.0.1:4444/wd/hub"/>
</waitfor>

<if>
<equals arg1="${selenium.timedout}" arg2="true"/>
<then>
<fail>
Unable to start Selenium2 standalone server on http://127.0.0.1:4444/wd/hub.
</fail>
</then>
</if>
</then>
<else>
<echo>Not starting Selenium2 standalone server. Hope that you have something else setup!</echo>
</else>
</if>
</target>

<target name="tests:phantomjs:kill"
description="Launches a GhostDriver." hidden="true">
<exec command="pgrep phantomjs | xargs kill" logoutput="true" level="${blt.exec_level}" passthru="true" />
<target name="tests:selenium:kill"
description="Kills Selenium standalone server process and any process running on port 4444." hidden="true">
<exec command="lsof -ti tcp:4444 | xargs kill" logoutput="false" level="${blt.exec_level}" passthru="true" checkreturn="false" />
<exec command="pgrep selenium | xargs kill" logoutput="false" level="${blt.exec_level}" passthru="true" checkreturn="false" />
</target>

<!-- Execute PHPUnit tests. -->
Expand Down
1 change: 1 addition & 0 deletions scripts/drupal-vm/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ npm_config_prefix: "/home/{{ drupalvm_user }}/.npm-global"
installed_extras:
- adminer
- nodejs
- java

# Use PHP 5.6 and change package names to work with 5.6.
php_version: "5.6"
Expand Down
19 changes: 19 additions & 0 deletions scripts/linux/install-chrome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Installs chromedriver and chrome for Linux 64 bit systems.
# Requires Trusty or higher.
# example usage `./install-chrome.sh usr/local/bin`

# Scripts expect argument specifying bin dir.
BIN_DIR=$1

if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Download google chrome.
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb

# Installs chromedriver for Linux 64 bit systems.
wget -N http://chromedriver.storage.googleapis.com/2.24/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
mv -f chromedriver $BIN_DIR
fi
8 changes: 7 additions & 1 deletion scripts/pipelines/acquia-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ events:
type: script
script:
- export PATH=$PATH:$BUILD_DIR/vendor/bin
- drupal init
# Install chromedriver.
- ./vendor/acquia/blt/scripts/linux/chromedriver.sh $BUILD_DIR/vendor/bin
# Initialize xvfb (see https://docs.travis-ci.com/user/gui-and-headless-browsers)
- sudo apt-get install xvfb
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
# The local.hostname must be set to 127.0.0.1:8888 because we are using drush runserver to test the site.
- drupal init
- drupal yaml:update:value project.yml project.local.hostname '127.0.0.1:8888'
- blt -Dbehat.run-server=true -Dcreate_alias=false -Dbehat.launch-phantom=true ci:build:validate:test

Expand Down
43 changes: 16 additions & 27 deletions template/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@
"drupal/search_api": "8.1.0-alpha14",
"drupal/search_api_solr": "8.1.0-alpha3",
"drupal/security_review": "8.*",
"drupal-composer/drupal-security-advisories": "8.0.x-dev",
"roave/security-advisories": "dev-master"
"drupal-composer/drupal-security-advisories": "8.0.x-dev"
},
"require-dev": {
"behat/behat": "3.0.*",
"behat/mink": "~1.7",
"behat/mink-browserkit-driver": "*",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*",
"drupal/coder": "~8.2",
"drupal/drupal-extension": "~3.0",
"drush/drush": "^9.0",
"drupal-composer/drupal-scaffold": "^2.0.0",
"jakoch/phantomjs-installer": "dev-master as 1.9.8",
"jarnaiz/behat-junit-formatter": "^1.2",
"phing/phing": "~2",
"phpunit/phpunit": "~5.4",
"squizlabs/php_codesniffer": "2.*"
"behat/behat": "^3.0",
"behat/mink": "~1.7",
"behat/mink-selenium2-driver": "*",
"drupal/coder": "~8.2",
"drupal/drupal-extension": "^3.2",
"drush/drush": "^9.0",
"drupal-composer/drupal-scaffold": "^2.0.0",
"jarnaiz/behat-junit-formatter": "^1.2",
"phing/phing": "~2",
"phpunit/phpunit": "~5.4",
"se/selenium-server-standalone": "^2.53",
"squizlabs/php_codesniffer": "2.*"
},
"autoload-dev": {
"psr-4": {
Expand All @@ -60,6 +56,9 @@
},
"drupal/features": {
"Bundle support": "https://www.drupal.org/files/issues/features-2808303-2.patch"
},
"drupal/lightning": {
"Fix failing Behat test for Selenium": "https://www.drupal.org/files/issues/issue-158-selenium-behat-tests.patch"
}
}
},
Expand All @@ -68,16 +67,6 @@
"nuke": [
"rm -rf vendor composer.lock",
"@composer install"
],
"install-phantomjs": [
"rm -rf vendor/bin/phantomjs",
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-install-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-update-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
]
},
"minimum-stability": "dev",
Expand Down
7 changes: 0 additions & 7 deletions template/tests/behat/example.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ local:
base_url: ${project.local.uri}
# set default command for "Show last response" step.
show_cmd: "open %s"
# ADDITIONAL OPTIONS FOR WEB DRIVERS
# use the following 3 lines to use phantomjs
# browser_name: phantomjs
# selenium2:
# wd_host: "http://localhost:4444/wd/hub"
# browser: chrome
#
# use the following lines to disable SSL authentication for goutte.
# goutte:
# guzzle_parameters:
Expand Down