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)
7 # Copyright 2020, Franck Villaume - TrivialDev
9 # This file is part of FusionForge. FusionForge is free software;
10 # you can redistribute it and/or modify it under the terms of the
11 # GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the Licence, or (at your option)
15 # FusionForge is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 export DEBIAN_FRONTEND=noninteractive
37 export INSTALL_METHOD=${1%/*}
38 export INSTALL_OS=${1#*/}
41 case $INSTALL_METHOD in
43 *) echo "Unknown install method"
49 *) echo "Unknown install OS"
56 if [[ `rpm -qi httpd-itk | grep Release | awk '{print $3}'` != '1.el7' ]]; then
57 echo 'WARNING: WORKAROUND for docker/lxc. Downgrade httpd-itk.'
58 echo 'TODO: check for newer version. Debian not impacted.'
59 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
60 yum downgrade -y /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
61 rm -f /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
62 service httpd restart || true
69 # Selenium dependencies and test dependencies
70 # psmisc for db_reload.sh:killall
71 # rsyslog to get e.g. sshd error log
72 if [ -e /etc/debian_version ]; then
73 apt-get -y install wget firefox-esr net-tools
74 if grep -q ^8 /etc/debian_version; then
75 apt-get -y install phpunit phpunit-selenium psmisc rsyslog patch
76 apt-get -y install -t jessie-backports openjdk-8-jdk
78 apt-get -y install php-curl unzip composer psmisc rsyslog default-jre patch
79 mkdir -p /usr/local/share/php
80 pushd /usr/local/share/php
81 composer --no-plugins --no-scripts require phpunit/phpunit
82 composer --no-plugins --no-scripts require phpunit/phpunit-selenium:dev-master
86 yum -y install wget firefox java-1.8.0-openjdk
87 yum --enablerepo=epel install -y php-phpunit-PHPUnit php-phpunit-PHPUnit-Selenium psmisc net-tools patch
90 # Install selenium (no packaged version available)
94 SELENIUMURL=http://selenium-release.storage.googleapis.com/$SELENIUMMAJOR.$SELENIUMMINOR/selenium-server-standalone-$SELENIUMMAJOR.$SELENIUMMINOR.$SELENIUMMICRO.jar
95 mkdir -p /usr/share/selenium/
96 http_proxy=$PROXY wget -v -c $SELENIUMURL \
97 -O /usr/share/selenium/selenium-server.jar
103 GECKODRIVERURL=https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVERMAJOR.$GECKODRIVERMINOR.$GECKODRIVERMICRO/geckodriver-v$GECKODRIVERMAJOR.$GECKODRIVERMINOR.$GECKODRIVERMICRO-linux64.tar.gz
104 mkdir -p /usr/share/geckodriver/
105 rm -f /usr/share/geckodriver/geckodriver
106 http_proxy=$PROXY wget -c $GECKODRIVERURL \
107 -O /usr/share/geckodriver/geckodriver.tar.gz
109 tar -zxf /usr/share/geckodriver/geckodriver.tar.gz -C /usr/share/geckodriver/
110 chmod +x /usr/share/geckodriver/geckodriver
112 # Add alias to /etc/hosts
113 if ! grep -q ^$(hostname -i) /etc/hosts ; then
114 echo $(hostname -i) $(hostname -f) $(hostname)>> /etc/hosts
116 grep -q "^$(hostname -i).*$(forge_get_config scm_host)" /etc/hosts || sed -i -e "s/^$(hostname -i).*/& $(forge_get_config scm_host)/" /etc/hosts
118 #fix https://github.com/giorgiosironi/phpunit-selenium/issues/427
119 for i in /usr/share/*/PHPUnit/Extensions/Selenium2TestCase/Element.php /usr/local/share/php/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element.php ; do
120 if [ -e "$i" ] ; then
121 patch -N "$i" <<'EOF' || true
122 --- Element.php.dist 2014-11-02 09:23:27.000000000 +0000
123 +++ Element.php 2019-01-15 15:00:44.034513685 +0000
125 PHPUnit\Extensions\Selenium2TestCase_URL $parentFolder,
126 PHPUnit\Extensions\Selenium2TestCase_Driver $driver)
129 if (!isset($value['ELEMENT'])) {
130 - throw new InvalidArgumentException('Element not found.');
131 + foreach ($value as $lKey => $val) {
132 + if (substr($lKey,0,7) === "element") {
138 + throw new InvalidArgumentException('Element not found.');
143 - $url = $parentFolder->descend($value['ELEMENT']);
144 + $url = $parentFolder->descend($value[$key]);
145 return new self($driver, $url);
153 # Mitigate testsuite timeouts, cf.
154 # http://lists.fusionforge.org/pipermail/fusionforge-general/2015-November/002955.html
159 if ! grep -q '^export PGPASSFILE' /etc/apache2/envvars; then
160 echo 'export PGPASSFILE=' >> /etc/apache2/envvars
164 if ! grep -q '^PGPASSFILE' /etc/sysconfig/httpd; then
165 echo 'PGPASSFILE=' >> /etc/sysconfig/httpd
177 service cron stop || true
179 # Reset the database and repos to post-install/pristine state
180 $(dirname $0)/func/fixtures.sh --reset
181 $(dirname $0)/func/fixtures.sh --backup
185 FORGE_HOME=$(cd $(dirname $0)/..; pwd)
187 SELENIUM_RC_DIR=/var/log
188 SELENIUM_RC_HOST=$HOST
189 # URL for screenshots - cf. http://buildbot.fusionforge.org/env-vars.html
190 SELENIUM_RC_URL=${JOB_URL}ws/reports
191 # config.php will be loaded inside the functionnal test suite with
192 # require_once, in SeleniumForge.php
193 export SELENIUM_RC_DIR SELENIUM_RC_URL SELENIUM_RC_HOST HOST
195 # Add definitions for the PHP functionnal test suite
196 cat <<-EOF >$(dirname $0)/func/config.php
198 // Host where selenium-rc is running
199 define ('SELENIUM_RC_HOST', getenv('SELENIUM_RC_HOST'));
200 define ('SELENIUM_RC_DIR', getenv('SELENIUM_RC_DIR'));
202 // The forge's hostname
203 define ('HOST', getenv('HOST'));
205 // Base URL where FusionForge is installed
208 define('INSTALL_METHOD', getenv('INSTALL_METHOD'));
209 define('INSTALL_OS', getenv('INSTALL_OS'));
212 // DON'T MODIFY BELOW THIS LINE UNLESS YOU KNOW WHAT YOU DO
215 // These are deduced from the previous definitions.
217 // URL to access the application
218 define ('URL', 'https://'.HOST.'/');
220 // WSDL of the forges SOAP API
221 // define ('WSDL_URL', URL.'soap/index.php?wsdl');
222 define ('WSDL_URL', 'http://'.HOST.'/soap/index.php?wsdl');
225 echo "Starting Selenium"
226 killall -9 java || true
228 export PATH=/usr/share/geckodriver:/usr/lib/iceweasel:/usr/lib/firefox-esr:/usr/lib64/firefox:$PATH
230 java -Dwebdriver.gecko.driver=/usr/share/geckodriver/geckodriver -jar /usr/share/selenium/selenium-server.jar &
233 while [ $i -lt $timeout ] && ! netstat -tnl 2>/dev/null | grep -q :4444 && kill -0 $pid 2>/dev/null; do
234 echo "Waiting for Selenium..."
238 if [ $i = $timeout ]; then
239 echo "Selenium failed to start listener… lacking entropy? Trying again."
240 find / > /dev/null 2> /dev/null &
242 while [ $i -lt $timeout ] && ! netstat -tnl 2>/dev/null | grep -q :4444 && kill -0 $pid 2>/dev/null; do
243 echo "Waiting for Selenium..."
248 if [ $i = $timeout ] || ! kill -0 $pid 2>/dev/null; then
249 echo "Selenium failed to start!"
255 echo "Running PHPunit tests"
259 # Override test through parameter, useful when launching tests through buildbot/*.sh (e.g. SSH)
260 # Use the TESTGLOB environment variable otherwise
261 testname="func_tests.php"
262 if [ -n "$1" ] ; then
266 if [ -x /usr/local/share/php/vendor/bin/phpunit ] ; then
267 phpunit=/usr/local/share/php/vendor/bin/phpunit
272 # For some reason PHPunit thinks all methods are tests
273 # …hence the --filter ::test to enforce that
274 # otherwise shared methods such as login() and logout() are run like tests and fail
275 timeout 2h $phpunit --filter ::test --verbose --debug --stop-on-failure --log-junit $SELENIUM_RC_DIR/phpunit-selenium.xml $testname || retcode=$?
278 echo "phpunit returned with code $retcode"
282 killall -9 firefox-bin # debian
283 killall -9 firefox # centos
284 killall -9 java # kill java stuffs