With DalekJS you can automate your functional GUI tests very easy. This article describe how to prepare the test environment on CentOS.
Setup
First, the necessary packages are installed.
# install EPEL (Extra Packages for Enterprise Linux) $ yum install -y epel-release # check repositories $ yum repolist # update all $ yum -y update # install packages $ yum install -y vim nodejs npm bzip2 freetype fontconfig # check versions of nodejs and npm $ node --version $ npm --version # change to tmp folder $ cd /tmp/ # download PhantomJS and unzip $ curl -O https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2 $ tar xvf phantomjs-1.9.2-linux-x86_64.tar.bz2 # copy binary, delete unneeded files and check version $ cp phantomjs-1.9.2-linux-x86_64/bin/phantomjs /usr/local/bin/ $ rm -fr phantomjs-1.9.2-linux-x86_64 $ rm -f phantomjs-1.9.2-linux-x86_64.tar.bz2 $ phantomjs --version # install dalek-cli (global) and check version $ npm install dalek-cli -g $ dalek --version
It is also possible to compile PhantomJS itself, but this takes a lot of time.
Prepare test project
Once all is installed without any issues you can start to create the test project.
# change to home folder $ cd ~/ # create project folder and change into $ mkdir DalekTest && cd DalekTest # create package.json interactively $ npm init # install dalekjs on project $ npm install dalekjs --save-dev
Create test case
Now it is time for the first Test Case. I have used the example from Dalek website.
# create test case file $ touch test_title.js # insert content $ vim test_title.js
module.exports = {'Page title is correct': function (test) { test .open('http://google.com') .assert.title().is('Google', 'It has title') .done(); } };
Run test
By default DalekJS use PhantomJS as browser. For running the test case simple use dalek command and as argument the test case file (*.js).
# run test case $ dalek test_title.js