2 # Install and start Selenium in background, pass configuration, and
3 # run PHPUnit functional testsuite
5 # Copyright (C) 2011 Olivier Berger - Institut Telecom
6 # Copyright (C) 2014, 2015 Inria (Sylvain Beucler)
8 # This file is part of FusionForge. FusionForge is free software;
9 # you can redistribute it and/or modify it under the terms of the
10 # GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the Licence, or (at your option)
14 # FusionForge is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 export DEBIAN_FRONTEND=noninteractive
36 export INSTALL_METHOD=${1%/*}
37 export INSTALL_OS=${1#*/}
40 case $INSTALL_METHOD in
42 *) echo "Unknown install method"
48 *) echo "Unknown install OS"
55 if [[ `rpm -qi httpd-itk | grep Release | awk '{print $3}'` != '1.el7' ]]; then
56 echo 'WARNING: WORKAROUND for docker/lxc. Downgrade httpd-itk.'
57 echo 'TODO: check for newer version. Debian not impacted.'
58 curl https://kojipkgs.fedoraproject.org//packages/httpd-itk/2.4.7.04/1.el7/x86_64/httpd-itk-2.4.7.04-1.el7.x86_64.rpm -o /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
59 yum downgrade -y /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
60 rm -f /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
61 service httpd restart || true
68 # Selenium dependencies and test dependencies
69 # psmisc for db_reload.sh:killall
70 # rsyslog to get e.g. sshd error log
71 if [ -e /etc/debian_version ]; then
72 apt-get -y install wget firefox-esr net-tools
73 if grep -q ^8 /etc/debian_version; then
74 apt-get -y install phpunit phpunit-selenium psmisc rsyslog patch
75 apt-get -y install -t jessie-backports openjdk-8-jdk
77 apt-get -y install php-curl unzip composer psmisc rsyslog default-jre patch
78 mkdir -p /usr/local/share/php
79 pushd /usr/local/share/php
80 composer --no-plugins --no-scripts require phpunit/phpunit
81 composer --no-plugins --no-scripts require phpunit/phpunit-selenium
85 yum -y install wget firefox java-1.8.0-openjdk
86 yum --enablerepo=epel install -y php-phpunit-PHPUnit php-phpunit-PHPUnit-Selenium psmisc net-tools patch
89 # Install selenium (no packaged version available)
93 SELENIUMURL=http://selenium-release.storage.googleapis.com/$SELENIUMMAJOR.$SELENIUMMINOR/selenium-server-standalone-$SELENIUMMAJOR.$SELENIUMMINOR.$SELENIUMMICRO.jar
94 mkdir -p /usr/share/selenium/
95 http_proxy=$PROXY wget -v -c $SELENIUMURL \
96 -O /usr/share/selenium/selenium-server.jar
102 GECKODRIVERURL=https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVERMAJOR.$GECKODRIVERMINOR.$GECKODRIVERMICRO/geckodriver-v$GECKODRIVERMAJOR.$GECKODRIVERMINOR.$GECKODRIVERMICRO-linux64.tar.gz
103 mkdir -p /usr/share/geckodriver/
104 rm -f /usr/share/geckodriver/geckodriver*
105 http_proxy=$PROXY wget -c $GECKODRIVERURL \
106 -O /usr/share/geckodriver/geckodriver.tar.gz
108 tar -zxf /usr/share/geckodriver/geckodriver.tar.gz -C /usr/share/geckodriver/
109 chmod +x /usr/share/geckodriver/geckodriver
111 # Add alias to /etc/hosts
112 if ! grep -q ^$(hostname -i) /etc/hosts ; then
113 echo $(hostname -i) $(hostname -f) $(hostname)>> /etc/hosts
115 grep -q "^$(hostname -i).*$(forge_get_config scm_host)" /etc/hosts || sed -i -e "s/^$(hostname -i).*/& $(forge_get_config scm_host)/" /etc/hosts
117 #fix https://github.com/giorgiosironi/phpunit-selenium/issues/427
118 for i in /usr/share/*/PHPUnit/Extensions/Selenium2TestCase/Element.php /usr/local/share/php/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element.php ; do
119 if [ -e "$i" ] ; then
120 patch -N "$i" <<'EOF' || true
121 --- Element.php.dist 2014-11-02 09:23:27.000000000 +0000
122 +++ Element.php 2019-01-15 15:00:44.034513685 +0000
124 PHPUnit_Extensions_Selenium2TestCase_URL $parentFolder,
125 PHPUnit_Extensions_Selenium2TestCase_Driver $driver)
128 if (!isset($value['ELEMENT'])) {
129 - throw new InvalidArgumentException('Element not found.');
130 + foreach ($value as $lKey => $val) {
131 + if (substr($lKey,0,7) === "element") {
137 + throw new InvalidArgumentException('Element not found.');
142 - $url = $parentFolder->descend($value['ELEMENT']);
143 + $url = $parentFolder->descend($value[$key]);
144 return new self($driver, $url);
152 # Mitigate testsuite timeouts, cf.
153 # http://lists.fusionforge.org/pipermail/fusionforge-general/2015-November/002955.html
158 if ! grep -q '^export PGPASSFILE' /etc/apache2/envvars; then
159 echo 'export PGPASSFILE=' >> /etc/apache2/envvars
163 if ! grep -q '^PGPASSFILE' /etc/sysconfig/httpd; then
164 echo 'PGPASSFILE=' >> /etc/sysconfig/httpd
176 service cron stop || true
178 # Reset the database and repos to post-install/pristine state
179 $(dirname $0)/func/fixtures.sh --reset
180 $(dirname $0)/func/fixtures.sh --backup
184 FORGE_HOME=$(cd $(dirname $0)/..; pwd)
186 SELENIUM_RC_DIR=/var/log
187 SELENIUM_RC_HOST=$HOST
188 # URL for screenshots - cf. http://buildbot.fusionforge.org/env-vars.html
189 SELENIUM_RC_URL=${JOB_URL}ws/reports
190 # config.php will be loaded inside the functionnal test suite with
191 # require_once, in SeleniumForge.php
192 export SELENIUM_RC_DIR SELENIUM_RC_URL SELENIUM_RC_HOST HOST
194 # Add definitions for the PHP functionnal test suite
195 cat <<-EOF >$(dirname $0)/func/config.php
197 // Host where selenium-rc is running
198 define ('SELENIUM_RC_HOST', getenv('SELENIUM_RC_HOST'));
199 define ('SELENIUM_RC_DIR', getenv('SELENIUM_RC_DIR'));
201 // The forge's hostname
202 define ('HOST', getenv('HOST'));
204 // Base URL where FusionForge is installed
207 define('INSTALL_METHOD', getenv('INSTALL_METHOD'));
208 define('INSTALL_OS', getenv('INSTALL_OS'));
211 // DON'T MODIFY BELOW THIS LINE UNLESS YOU KNOW WHAT YOU DO
214 // These are deduced from the previous definitions.
216 // URL to access the application
217 define ('URL', 'https://'.HOST.'/');
219 // WSDL of the forges SOAP API
220 // define ('WSDL_URL', URL.'soap/index.php?wsdl');
221 define ('WSDL_URL', 'http://'.HOST.'/soap/index.php?wsdl');
224 echo "Starting Selenium"
225 killall -9 java || true
227 export PATH=/usr/share/geckodriver:/usr/lib/iceweasel:/usr/lib/firefox-esr:/usr/lib64/firefox:$PATH
229 java -Dwebdriver.gecko.driver=/usr/share/geckodriver/geckodriver -jar /usr/share/selenium/selenium-server.jar &
232 while [ $i -lt $timeout ] && ! netstat -tnl 2>/dev/null | grep -q :4444 && kill -0 $pid 2>/dev/null; do
233 echo "Waiting for Selenium..."
237 if [ $i = $timeout ]; then
238 echo "Selenium failed to start listener… lacking entropy? Trying again."
239 find / > /dev/null 2> /dev/null &
241 while [ $i -lt $timeout ] && ! netstat -tnl 2>/dev/null | grep -q :4444 && kill -0 $pid 2>/dev/null; do
242 echo "Waiting for Selenium..."
247 if [ $i = $timeout ] || ! kill -0 $pid 2>/dev/null; then
248 echo "Selenium failed to start!"
254 echo "Running PHPunit tests"
258 # Override test through parameter, useful when launching tests through buildbot/*.sh (e.g. SSH)
259 # Use the TESTGLOB environment variable otherwise
260 testname="func_tests.php"
261 if [ -n "$1" ] ; then
265 if [ -x /usr/local/share/php/vendor/bin/phpunit ] ; then
266 phpunit=/usr/local/share/php/vendor/bin/phpunit
271 timeout 2h $phpunit --verbose --debug --stop-on-failure --log-junit $SELENIUM_RC_DIR/phpunit-selenium.xml $testname || retcode=$?
274 echo "phpunit returned with code $retcode"
278 killall -9 firefox-bin # debian
279 killall -9 firefox # centos
280 killall -9 java # kill java stuffs