How to run protractor test cases in headless mode using xvfb.
Sudharsan Selvaraj
Principal Software Engineer | Ex-Amazon | Automation enthusiast
In recent times I am getting lot questions on how to automate protractor test cases using xvfb in jenkins and that's the reason why I'm creating this post. To start with Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. Xvfb performs all graphical operations in memory without showing any screen output. Let us assume that if you want to run automation cases in any server machine that doesn't have any display option, then we can use Xvfb to create a virtual display that can be used by the browser window to launch the web application. If you are using ubuntu based OS, then installing Xvfb is a very straight forward process. Just execute the below shell commands in terminal to install Xvfb and all its dependencies.
sudo apt-get update
sudo apt-get install -y xvfb
sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-cyrillic dbus-x11
To download and install google chrome, run the below commands.
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
That's it. Now Xvfb and google chrome will be installed successfully. In next step I will explain how the protractor process can be started using Xvfb display.
xvfb-run -a -e /dev/stdout -s "-screen 0 2920x2580x24" node node_modules/protractor/bin/protractor configuration.js?
The above command will start protractor using Xvfb display and launches chrome browser in headless mode. You can also set the display screen size using -s flag.
Hope this post is informative! Reach me out in case of any queries!
Founder | Optimworks Technologies Private Limited
7 年Nice post sudharsan selvaraj