When you start testing with Behat and Mink Selenium2 driver you also need a browser running. Because we develop on a virtualised server installing FireFox was a bit more tricky then I expected. Of course a search yielded some interesting results, but also a lot of crap. So here is a little writeup on how I managed to get it running to save you some time. An example playbook can be found at the bottom of this post. But beware: this is Debian only!
On Debian there is a package called iceweasel. This is a rebranded version of FireFox. Because of that there is no firefox package available in the default repositories.
We are using Ansible for configuration management (for both our production and develop environment) so I prefer a package above compiling shit because that’s much easier to automate. There are a couple of options to install FireFox trough package manager:
- add Linux Mint repository
- add ubuntuzilla repository
Using the Linux Mint repository I experienced some problems. The Ubuntuzilla repository worked like a charm. If you want to install manually just follow the instructions in their Wiki. After adding the repository you can install the firefox package:
1 |
$ sudo apt-get install firefox-mozilla-build |
To run Firefox headless you also need some display server and to emulate that we are going to use xvfb. Selenium requires Java, thus we install:
1 |
$ sudo apt-get install xvfb openjdk-7-jre-headless |
Download Selenium somewhere:
1 2 |
$ mkdir /opt/selenium $ wget -O /opt/selenium/selenium.jar http://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar |
You should be able to start Selenium now:
1 |
$ xvfb-run java -jar /opt/selenium/selenium.jar |
Starting by hand is a bit lame, so we use this startup script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
### BEGIN INIT INFO # Provides: selenium # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: selenium # Description: selenium with xvfb ### END INIT INFO XVFB=/usr/bin/xvfb-run XVFBARGS="java -jar /opt/selenium/selenium.jar" PIDFILE=/var/run/xvfb.pid case "$1" in start) echo -n "Starting virtual X frame buffer: Xvfb" start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS echo "." ;; stop) echo -n "Stopping virtual X frame buffer: Xvfb" # does not work with start-stop-daemon because of child processes read pid <$PIDFILE pkill -TERM -P $pid echo "." ;; restart) $0 stop $0 start ;; *) echo "Usage: /etc/init.d/selenium {start|stop|restart}" exit 1 esac exit 0 |
Copy this to /etc/init.d/selenium
and after that you can:
1 |
$ sudo service selenium start |
And when we create an Ansible playbook for all this we get:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
--- - name: Instal Selenium tasks: - apt_repository: repo="deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main" state=present - apt_key: id="C1289A29" keyserver=keyserver.ubuntu.com state=present - apt: name=iceweasel state=absent - apt: name={{ item }} state=present update_cache=yes with_items: - firefox-mozilla-build - openjdk-7-jre-headless - xvfb - file: name=/opt/selenium state=directory mode=0755 - get_url: url="http://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar" dest=/opt/selenium/selenium.jar - copy: src=selenium dest=/etc/init.d/selenium mode=0755 |