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

Commit 5684af8

Browse files
authored
Switching PhantomJS to Selenium (#520)
* Trying messy version... * Renaming chromedriver.sh. * Adding behat vars. * Moving xvbf to sh script. * Updating pipelines script. * Updating setup.xml. * Updating install.md. * Adding chrome install. * Adding xvbf back. * Removing xvbf script. * Reducing verbosity of kill targets. * Adding java to vm config. * Fixing failing Behat test.
1 parent 26c5c13 commit 5684af8

File tree

10 files changed

+104
-73
lines changed

10 files changed

+104
-73
lines changed

.travis.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Note that the example .travis.yml file for child projects lives in /install.
22
sudo: true
33
language: php
4+
dist: trusty
45

56
php:
67
- 5.6
@@ -24,7 +25,12 @@ notifications:
2425

2526
addons:
2627
ssh_known_hosts:
27-
- svn-5223.devcloud.hosting.acquia.com
28+
- svn-5223.devcloud.hosting.acquia.com
29+
apt:
30+
packages:
31+
- mysql-server-5.6
32+
- mysql-client-core-5.6
33+
- mysql-client-5.6
2834

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

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

5870
before_script:
5971
# Clear drush release history cache, to pick up new releases.

INSTALL.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Ensure that [Xcode](https://itunes.apple.com/us/app/xcode/id497799835?mt=12) is
2020
Then install the minimum dependencies for BLT. The preferred method is via Homebrew, though you could install these yourself without a package manager.
2121

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

2626
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).
@@ -29,6 +29,10 @@ If you'd like to create a VM with BLT, you will require the following additional
2929
brew install ansible
3030
brew cask install virtualbox vagrant
3131

32+
If you'd like to execute Behat tests from the host machine, you will need Java:
33+
34+
brew cask install java
35+
3236
### Windows
3337

3438
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.

phing/build.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
behat:
22
config: ${repo.root}/tests/behat/local.yml
3+
haltonerror: true
4+
strict: true
35
profile: local
46
# If true, `drush runserver` will be used for executing tests.
57
run-server: false
68
# This is used for ad-hoc creation of a server via `drush runserver`.
79
server-url: http://127.0.0.1:8888
8-
# If true, PhantomJS GhostDriver will be launched with Behat.
9-
launch-phantom: true
10+
# If true, Selenium standalone server will be launched with Behat.
11+
launch-selenium: true
1012
# An array of paths with behat tests that should be executed.
1113
paths:
1214
# - ${docroot}/modules
13-
# - ${docroot}/profiles
15+
- ${docroot}/profiles
1416
- ${repo.root}/tests/behat
1517
tags: '~ajax'
1618
verbose: ${blt.verbose}

phing/tasks/setup.xml

+1-15
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,14 @@
88
</target>
99

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

18-
<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"/>
19-
<if>
20-
<or>
21-
<istrue value="${phantomjs.missing}"/>
22-
<not><available file="${composer.bin}/phantomjs"/></not>
23-
<not><available file="${phantomjs.bin}"/></not>
24-
</or>
25-
<then>
26-
<exec dir="${repo.root}" command="composer install-phantom" checkreturn="true" logoutput="true" passthru="true" level="${blt.exec_level}"/>
27-
</then>
28-
<else>
29-
<echo>Found PhantomJS at ${phantomjs.bin}</echo>
30-
</else>
31-
</if>
32-
3319
<property file="${repo.root}/tests/behat/local.yml" prefix="behatConfig"/>
3420
<if>
3521
<or>

phing/tasks/tests.xml

+36-17
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

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

1717
<target name="tests:behat:execute" description="Executes behat tests against specific path." hidden="true">
@@ -32,8 +32,8 @@
3232
config="${behat.config}"
3333
profile="${behat.profile}"
3434
verbose="${behat.verbose}"
35-
strict="true"
36-
haltonerror="false"
35+
strict="${behat.strict}"
36+
haltonerror="${behat.haltonerror}"
3737
returnProperty="behatPass"
3838
out="std,${reports.localDir}"
3939
format="pretty,junit"
@@ -44,7 +44,7 @@
4444
<!-- A non-zero returns status indicates failure. -->
4545
<not><equals arg1="${behatPass}" arg2="0"/></not>
4646
<then>
47-
<phingcall target="tests:phantomjs:kill"/>
47+
<phingcall target="tests:selenium:kill"/>
4848
<fail message="One ore more Behat tests failed." />
4949
</then>
5050
<else>
@@ -58,30 +58,49 @@
5858
</if>
5959
</target>
6060

61-
<target name="tests:phantomjs:launch"
62-
description="Launches a GhostDriver."
61+
<target name="tests:selenium:launch"
62+
description="Launches Selenium standalone server."
6363
hidden="true">
6464

6565
<if>
66-
<equals arg1="${behat.launch-phantom}" arg2="true"/>
66+
<equals arg1="${behat.launch-selenium}" arg2="true"/>
6767
<then>
68-
<echo message="Launching PhantomJS GhostDriver." />
69-
<exec command="${composer.bin}/phantomjs --webdriver=4444"
68+
<phingcall target="tests:selenium:kill"/>
69+
<echo message="Launching Selenium standalone server." />
70+
<touch file="${repo.root}/reports/selenium2.log"/>
71+
<property name="reports.selenium2" value="${reports.localDir}/selenium2.log"/>
72+
<exec command="${composer.bin}/selenium-server-standalone -port 4444 -log ${reports.selenium2}"
73+
dir="${repo.root}"
7074
passthru="true"
7175
spawn="true"
7276
checkreturn="true"
73-
level="${blt.exec_level}"/>
74-
<echo message="Waiting 10 seconds for PhantomJS (http://127.0.0.1:4444) to become available."/>
75-
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second">
76-
<http url="http://127.0.0.1:4444"/>
77+
level="${blt.exec_level}"
78+
logoutput="false"/>
79+
<echo>Selenium2 logs are being written to ${reports.selenium2}.</echo>
80+
<echo message="Waiting 10 seconds for Selenium standalone server (http://127.0.0.1:4444) to become available."/>
81+
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second" timeoutproperty="selenium.timedout">
82+
<http url="http://127.0.0.1:4444/wd/hub"/>
7783
</waitfor>
84+
85+
<if>
86+
<equals arg1="${selenium.timedout}" arg2="true"/>
87+
<then>
88+
<fail>
89+
Unable to start Selenium2 standalone server on http://127.0.0.1:4444/wd/hub.
90+
</fail>
91+
</then>
92+
</if>
7893
</then>
94+
<else>
95+
<echo>Not starting Selenium2 standalone server. Hope that you have something else setup!</echo>
96+
</else>
7997
</if>
8098
</target>
8199

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

87106
<!-- Execute PHPUnit tests. -->

scripts/drupal-vm/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ npm_config_prefix: "/home/{{ drupalvm_user }}/.npm-global"
4646
installed_extras:
4747
- adminer
4848
- nodejs
49+
- java
4950

5051
# Use PHP 5.6 and change package names to work with 5.6.
5152
php_version: "5.6"

scripts/linux/install-chrome.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
# Installs chromedriver and chrome for Linux 64 bit systems.
3+
# Requires Trusty or higher.
4+
# example usage `./install-chrome.sh usr/local/bin`
5+
6+
# Scripts expect argument specifying bin dir.
7+
BIN_DIR=$1
8+
9+
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
10+
# Download google chrome.
11+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
12+
sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb
13+
14+
# Installs chromedriver for Linux 64 bit systems.
15+
wget -N http://chromedriver.storage.googleapis.com/2.24/chromedriver_linux64.zip
16+
unzip chromedriver_linux64.zip
17+
chmod +x chromedriver
18+
mv -f chromedriver $BIN_DIR
19+
fi

scripts/pipelines/acquia-pipelines.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ events:
2525
type: script
2626
script:
2727
- export PATH=$PATH:$BUILD_DIR/vendor/bin
28-
- drupal init
28+
# Install chromedriver.
29+
- ./vendor/acquia/blt/scripts/linux/chromedriver.sh $BUILD_DIR/vendor/bin
30+
# Initialize xvfb (see https://docs.travis-ci.com/user/gui-and-headless-browsers)
31+
- sudo apt-get install xvfb
32+
- export DISPLAY=:99.0
33+
- sh -e /etc/init.d/xvfb start
2934
# The local.hostname must be set to 127.0.0.1:8888 because we are using drush runserver to test the site.
35+
- drupal init
3036
- drupal yaml:update:value project.yml project.local.hostname '127.0.0.1:8888'
3137
- blt -Dbehat.run-server=true -Dcreate_alias=false -Dbehat.launch-phantom=true ci:build:validate:test
3238

template/composer.json

+16-27
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,21 @@
2121
"drupal/search_api": "8.1.0-alpha14",
2222
"drupal/search_api_solr": "8.1.0-alpha3",
2323
"drupal/security_review": "8.*",
24-
"drupal-composer/drupal-security-advisories": "8.0.x-dev",
25-
"roave/security-advisories": "dev-master"
24+
"drupal-composer/drupal-security-advisories": "8.0.x-dev"
2625
},
2726
"require-dev": {
28-
"behat/behat": "3.0.*",
29-
"behat/mink": "~1.7",
30-
"behat/mink-browserkit-driver": "*",
31-
"behat/mink-extension": "*",
32-
"behat/mink-goutte-driver": "*",
33-
"behat/mink-selenium2-driver": "*",
34-
"drupal/coder": "~8.2",
35-
"drupal/drupal-extension": "~3.0",
36-
"drush/drush": "^9.0",
37-
"drupal-composer/drupal-scaffold": "^2.0.0",
38-
"jakoch/phantomjs-installer": "dev-master as 1.9.8",
39-
"jarnaiz/behat-junit-formatter": "^1.2",
40-
"phing/phing": "~2",
41-
"phpunit/phpunit": "~5.4",
42-
"squizlabs/php_codesniffer": "2.*"
27+
"behat/behat": "^3.0",
28+
"behat/mink": "~1.7",
29+
"behat/mink-selenium2-driver": "*",
30+
"drupal/coder": "~8.2",
31+
"drupal/drupal-extension": "^3.2",
32+
"drush/drush": "^9.0",
33+
"drupal-composer/drupal-scaffold": "^2.0.0",
34+
"jarnaiz/behat-junit-formatter": "^1.2",
35+
"phing/phing": "~2",
36+
"phpunit/phpunit": "~5.4",
37+
"se/selenium-server-standalone": "^2.53",
38+
"squizlabs/php_codesniffer": "2.*"
4339
},
4440
"autoload-dev": {
4541
"psr-4": {
@@ -60,6 +56,9 @@
6056
},
6157
"drupal/features": {
6258
"Bundle support": "https://www.drupal.org/files/issues/features-2808303-2.patch"
59+
},
60+
"drupal/lightning": {
61+
"Fix failing Behat test for Selenium": "https://www.drupal.org/files/issues/issue-158-selenium-behat-tests.patch"
6362
}
6463
}
6564
},
@@ -68,16 +67,6 @@
6867
"nuke": [
6968
"rm -rf vendor composer.lock",
7069
"@composer install"
71-
],
72-
"install-phantomjs": [
73-
"rm -rf vendor/bin/phantomjs",
74-
"PhantomInstaller\\Installer::installPhantomJS"
75-
],
76-
"post-install-cmd": [
77-
"PhantomInstaller\\Installer::installPhantomJS"
78-
],
79-
"post-update-cmd": [
80-
"PhantomInstaller\\Installer::installPhantomJS"
8170
]
8271
},
8372
"minimum-stability": "dev",

template/tests/behat/example.local.yml

-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ local:
2929
base_url: ${project.local.uri}
3030
# set default command for "Show last response" step.
3131
show_cmd: "open %s"
32-
# ADDITIONAL OPTIONS FOR WEB DRIVERS
33-
# use the following 3 lines to use phantomjs
34-
# browser_name: phantomjs
35-
# selenium2:
36-
# wd_host: "http://localhost:4444/wd/hub"
37-
# browser: chrome
38-
#
3932
# use the following lines to disable SSL authentication for goutte.
4033
# goutte:
4134
# guzzle_parameters:

0 commit comments

Comments
 (0)