Protractor with Jenkins and Headless Chrome (Xvfb) Setup

28 / Sep / 2016 by Mohit Kumar 0 comments

“Protractor is an end-to-end test framework for AngularJS applications. Protractor is to run one or multiple tests against your application running in a real browser, interacting with it as a user would.”

It is easier to check on GUI based system because it launches a browser automatically during the test.

But what about non-GUI? For example, we need to setup it up on Linux server in non-GUI mode or Jenkins server for CI/CD. It is possible through Xvfb.

Xvfb (X virtual framebuffer) is an in-memory display server used in a UNIX-like OS  (e.g., Linux). Xvfb enables one to run graphical applications without a display.”

Below are the steps which can help us to run Protractor test in non-GUI mode.


1: – Install JAVA
2: – Install Jenkins and a configured build section in Jenkins job
3: – Installed NodeJS

Install Protractor and Selenium WebDriver

curl -sL | sudo bash -
npm install protractor -g
ln /usr/lib/node_modules/protractor/selenium/chromedriver /usr/bin/chromedriver
webdriver-manager update
webdriver-manager start

Note: webdriver- If protractor installation fails with an error, Please check the ownership for logged in user, then execute above commands again
chown -R $(whoami) ~/.npm
chown -R $(whoami) /usr/local/lib/node_modules

Setup Headless Chrome browser

echo "deb stable main" | sudo tee -a /etc/apt/sources.list
wget -q -O - | sudo apt-key add -
apt-get update
apt-get install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
apt-get install google-chrome-stable
apt-get install xvfb gtk2-engines-pixbuf
apt-get install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
apt-get install imagemagick x11-apps dbus-x11

To launch the web driver with Xvfb at backend

Script is present in  /etc/init.d/selenium:

Xvfb -ac :99 -screen 0 1280x1024x16 &
#disown $1
export DISPLAY=:99
webdriver-manager start /dev/null 2>&1

Execute this script and verify the service on Port 4444.

Now, login into Jenkins and select associated job, where need to run this Protractor test.

In Post Build section (execute shell) enter the following:

protractor protractor_conf.js

Hope this helps you to integrate protractor with Jenkins. Xvfb may be useful for other browser dependent applications in non-GUI mode.


Leave a comment -