Setting up NightWatch on Linux Box

Goal: A linux box with selenium and chrome driver installed to run nightwatch.js automated UI tests.

Infrastructure: Centos 7

Before everything else

yum update

Install Java

sudo yum install java

Install xvfb

sudo yum -y install firefox Xvfb libXfont Xorg
sudo yum -y groupinstall "X Window System" "Desktop" "Fonts" "General Purpose Desktop"

Install google chrome by running the install_chrome bash script at

http://chrome.richardlloyd.org.uk/

Install chromedriver for linux

wget http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver

Install the selenium standalone server

wget http://selenium-release.storage.googleapis.com/2.52/selenium-server-standalone-2.52.0.jar
mv selenium-server-standalone-2.52.0.jar /opt/

Run xvfb:

Xvfb :1 -screen 5 1366x768x8

export DISPLAY=:1.5

export LD_LIBRARY_PATH=/opt/google/chrome/lib
iptables -N SELENIUM
iptables -A INPUT -p tcp --dport 4444 -j SELENIUM
iptables -A SELENIUM -p tcp --dport 4444 -s 127.0.0.1 -j ACCEPT
iptables -A SELENIUM -p tcp --dport 4444 -j DROP

Start the selenium server:

java -jar selenium-server-standalone-2.30.0.jar -Dwebdriver.chrome.bin=/path/to/google-chrome -Dwebdriver.chrome.driver=/path/to/chromedriver

Run the nightwatch tests

./nightwatch -e jenkins

The selenium server log should output something similar to this:

Mar 19, 2013 10:07:27 AM org.openqa.grid.selenium.GridLauncher main INFO: Launching a standalone server

Setting system property webdriver.chrome.bin to {location of google-chrome}

Setting system property webdriver.chrome.driver to {location of chromedriver}

10:07:34.258 INFO – RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub

10:07:34.259 INFO – Version Jetty/5.1.x 10:07:34.259 INFO – Started HttpContext[/selenium-server/driver,/selenium-server/driver] …

The ChromeDriver server (Web app developers only)

If you’re a Web app developer and have just installed Google Chrome via my script, you may also be trying to run the ChromeDriver server on RHEL/CentOS 6 to automate the testing of your app. Sadly, after downloading and unpacking it (and making sure you got the latest 32-bit or 64-bit version), you’ll find it has a familiar library problem very similar to Google Chrome’s. However, this is easily fixed by simply using the extra libraries from your Google Chrome installation:

export LD_LIBRARY_PATH=/opt/google/chrome/lib
./chromedriver
[Should output: Starting ChromeDriver (v2.9.248304) on port 9515]