Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

[WIP] Enable running selenium tests against release builds of Firefox as well as nightly. #405

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ before_install:
- export PATH=$PATH:$HOME/.local/bin
- pip install --install-option="--prefix=$HOME/.local" -r require.pip --use-mirrors

script:
- make test
- make release_all

# The /check url below will check to see if the repository is updated and deploy
# if necessary.
after_success:
Expand Down
39 changes: 27 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
FRONTEND_CMD = "python -m unittest discover -v test/frontend"
FUNCTIONAL_CMD = "python -m unittest discover -v test/functional"

NODE_LOCAL_BIN=./node_modules/.bin
NODE_ENV?=development # by default we are in development mode

REPEAT_TIMES ?= 10
REPEAT_TEST ?= $(FUNCTIONAL_CMD)

ifeq ($(shell echo ${NODE_ENV}), development)
SESSION_SECRET?=unguessable # default secret for development and test mode
endif
Expand Down Expand Up @@ -60,27 +67,35 @@ cover_server:
$(NODE_LOCAL_BIN)/_mocha -- test/server
@echo aim your browser at coverage/lcov-report/index.html for details

# XXX refactor this file to not invoke run_selenium_test.sh twice, and call
# other targets

.PHONY: selenium_all
selenium_all:
bin/run_selenium_test.sh "python -m unittest discover -v test/frontend" \
"python -m unittest discover -v test/functional"
bin/run_selenium_test.sh $(FRONTEND_CMD) \
$(FUNCTIONAL_CMD)

.PHONY: selenium
selenium:
bin/run_selenium_test.sh "python -m unittest discover -v test/functional"
.PHONY: release_all
release_all:
FULL_SELENIUM_DEBUG=1 RELEASE_FIREFOX=1 bin/run_selenium_test.sh $(FRONTEND_CMD)
# $(FUNCTIONAL_CMD)

.PHONY: selenium functional
selenium functional:
bin/run_selenium_test.sh $(FUNCTIONAL_CMD)

.PHONY: release_selenium release_functional
release_selenium release_functional:
RELEASE_FIREFOX=1 bin/run_selenium_test.sh $(FUNCTIONAL_CMD)

.PHONY: selenium-repeat
REPEAT_TIMES ?= 10
REPEAT_TEST ?= -m unittest discover -v test/functional
selenium-repeat:
bin/run_selenium_test.sh "bin/repeat_loop.sh $(REPEAT_TIMES) python $(REPEAT_TEST)"
bin/run_selenium_test.sh "bin/repeat_loop.sh $(REPEAT_TIMES) $(REPEAT_TEST)"

.PHONY: frontend
frontend:
bin/run_selenium_test.sh "python -m unittest discover -v test/frontend"
bin/run_selenium_test.sh $(FRONTEND_CMD)

.PHONY: release_frontend
release_frontend:
RELEASE_FIREFOX=1 bin/run_selenium_test.sh $(FRONTEND_CMD)

PINPANEL_DIR ?= bin/PinPanel
PINPANEL_SRCS ?= $(PINPANEL_DIR)/install.rdf $(PINPANEL_DIR)/bootstrap.js
Expand Down
6 changes: 5 additions & 1 deletion bin/firefox
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env bash
cat `pwd`/test/functional/user.js >> $XRE_PROFILE_PATH/user.js
if [ `uname` == "Darwin" ]; then
/Applications/FirefoxNightly.app/Contents/MacOS/firefox $@
if [ "$RELEASE_FIREFOX" = "1" ]; then
/Applications/Firefox.app/Contents/MacOS/firefox $@
else
/Applications/FirefoxNightly.app/Contents/MacOS/firefox $@
fi
elif [ -e /usr/bin/firefox-nightly ]; then
/usr/bin/firefox-nightly $@
else
Expand Down
89 changes: 70 additions & 19 deletions bin/selenium.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
#!/bin/bash

FIREFOX_BZIP2_FILENAME="firefox-30.0a1.en-US.linux-x86_64.tar.bz2"
FIREFOX_BZIP2_URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla-central/$FIREFOX_BZIP2_FILENAME"
FIREFOX_NIGHTLY_BZIP2_FILENAME="firefox-30.0a1.en-US.linux-x86_64.tar.bz2"
FIREFOX_NIGHTLY_BZIP2_URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla-central/$FIREFOX_NIGHTLY_BZIP2_FILENAME"

FIREFOX_RELEASE_BZIP2_FILENAME="firefox-27.0.tar.bz2"
FIREFOX_RELEASE_BZIP2_URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-x86_64/en-US/$FIREFOX_RELEASE_BZIP2_FILENAME"

if [ "$RELEASE_FIREFOX" == "1" ]; then
FIREFOX_BZIP2_FILENAME=$FIREFOX_RELEASE_BZIP2_FILENAME
FIREFOX_BZIP2_URL=$FIREFOX_RELEASE_BZIP2_URL
else
FIREFOX_BZIP2_FILENAME=$FIREFOX_NIGHTLY_BZIP2_FILENAME
FIREFOX_BZIP2_URL=$FIREFOX_NIGHTLY_BZIP2_URL
fi

SELENIUM_JAR_FILENAME="selenium-server-standalone-2.35.0d.jar"
SELENIUM_JAR_URL="http://ftp.mozilla.org/pub/mozilla.org/webtools/selenium/socialapi/$SELENIUM_JAR_FILENAME"
SELENIUM_PID_FILE="/tmp/selenium-server-pid"
PWD=`pwd`

function getSeleniumPid() {
SELENIUM_PID=`ps -eo pid,args | grep $SELENIUM_JAR_FILENAME | grep -v grep | awk '{print $1}'`
}
# Initialise for first time around.
getSeleniumPid

if [[ "$(uname)" == "Linux" && -z "$DISABLE_XVFB" ]]; then
echo "Running the tests in a virtual frame buffer."
XVFB="xvfb-run"
fi

function getXVFBPid() {
XVFB_PID=`ps -eo pid,args | grep $XVFB | grep -v grep | awk '{print $1}'`
}
# Initialise for first time around.
getXVFBPid

install() {
if [ ! -f $SELENIUM_JAR_FILENAME ]; then
echo "Downloading $SELENIUM_JAR_URL"
curl $SELENIUM_JAR_URL > $SELENIUM_JAR_FILENAME
echo "Selenium server install in $SELENIUM_JAR_FILENAME"
fi
if [[ (`uname` != "Darwin") && (!(-e /usr/bin/firefox-nightly)) && (! -f $FIREFOX_BZIP2_FILENAME) ]]; then
echo "Downloading $FIREFOX_BZIP2_URL"
curl $FIREFOX_BZIP2_URL > $FIREFOX_BZIP2_FILENAME

if [[ (`uname` != "Darwin") && (!(-e /usr/bin/firefox-nightly))]]; then
if [ ! -f $FIREFOX_BZIP2_FILENAME ]; then
echo "Downloading $FIREFOX_BZIP2_URL"
curl $FIREFOX_BZIP2_URL > $FIREFOX_BZIP2_FILENAME
fi
if [ -e firefox ]; then
rm -rf firefox
fi
echo "Unpacking $FIREFOX_BZIP2_FILENAME"
tar -xjf $FIREFOX_BZIP2_FILENAME
echo "Done."
Expand All @@ -33,40 +67,57 @@ bootstrap_python() {
}

start() {
if [ -f $SELENIUM_PID_FILE ]; then
echo "Selenium server is already running ($SELENIUM_PID_FILE)"
if [ "$SELENIUM_PID" != "" ]; then
echo "Selenium server is already running (pid=$SELENIUM_PID)"
exit 1
fi

if [[ "$(uname)" == "Linux" && -z "$DISABLE_XVFB" ]]; then
echo "Running the tests in a virtual frame buffer."
XVFB="xvfb-run"
fi

# options are listed at http://code.google.com/p/selenium/wiki/FirefoxDriver
if [ $FULL_SELENIUM_DEBUG ]; then
$XVFB java -jar $SELENIUM_JAR_FILENAME -Dwebdriver.firefox.bin=$PWD/bin/firefox -Dwebdriver.log.file=$PWD/console.log -Dwebdriver.firefox.logfile=/dev/stdout &
else
$XVFB java -jar $SELENIUM_JAR_FILENAME -Dwebdriver.firefox.bin=$PWD/bin/firefox -Dwebdriver.log.file=$PWD/console.log -Dwebdriver.firefox.logfile=$PWD/firefox.log &>/dev/null &
fi
PID=$!
echo $PID > $SELENIUM_PID_FILE
CODE="000"
while [ $CODE != "200" ]; do
CODE=$(curl -sL -w "%{http_code}" http://localhost:4444/wd/hub -o /dev/null)
sleep 0.1
done
echo "Selenium server started ($SELENIUM_JAR_FILENAME, pid=$PID)"
echo "Selenium server started ($SELENIUM_JAR_FILENAME)"
}

stop() {
if [ ! -f $SELENIUM_PID_FILE ]; then
if [ "$SELENIUM_PID" = "" ]; then
echo "Selenium server not running"
exit 1
fi
cat $SELENIUM_PID_FILE | xargs kill -15
rm -f $SELENIUM_PID_FILE

echo "Stopping Selenium server..."
kill -15 $SELENIUM_PID

# Ensure the server has fully stopped, for cases where we run two commands together,
# e.g. travis.
getSeleniumPid

while [ "$SELENIUM_PID" != "" ]; do
sleep 0.5
getSeleniumPid
done
echo "Selenium server stopped"

if [ "$XVFB_PID" != "" ]; then
echo "Stopping XVFB"
kill -15 $XVFB_PID

getXVFBPid

while [ "$XVFB_PID" != "" ]; do
sleep 0.5
getXVFBPid
done

echo "XVFB stopped"
fi
}

case "$1" in
Expand Down