Protractor with Jenkins and Headless Chrome (Xvfb) Setup

28 / Sep / 2016 by Mohit Kumar 1 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.

Prerequisites

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

Install Protractor and Selenium WebDriver

[js]curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash –
npm install protractor -g
ln /usr/lib/node_modules/protractor/selenium/chromedriver /usr/bin/chromedriver
webdriver-manager update
webdriver-manager start[/js]

Untitled
——————————————————————————————————-
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

[js]
echo "deb stable main" | sudo tee -a /etc/apt/sources.list
wget -q -O – https://dl-ssl.google.com/linux/linux_signing_key.pub | 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
[/js]

To launch the web driver with Xvfb at backend

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

#!/bin/sh
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:

[js]cd $CODE_PATH
protractor protractor_conf.js[/js]

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

FOUND THIS USEFUL? SHARE IT

comments (1 “Protractor with Jenkins and Headless Chrome (Xvfb) Setup”)

  1. valentin

    i try to make this work in an angular 2 project created with the angular cli and jenkins on centOS 7.
    on my desktop its simple the ng e2e command to run the tests.
    now i tryied to make it work with Xvfb but i have problems that protractor then doesnt find the browser google-chrome or chromium cause as said on their(protractor) site browser name should be “chrome” “firefox”.
    i get:
    I/update – chromedriver: chromedriver_2.28 up to date
    I/launcher – Running 1 instances of WebDriver
    E/direct – Error code: 135
    E/direct – Error message: browserName google-chrome is not supported with directConnect.
    E/direct – Error: browserName google-chrome is not supported with directConnect.

    [
    askubuntu.com/questions/754382/how-do-i-start-chromium-browser-in-headless-mode-extension-randr-missing-on-d
    regarding to this i did “Xvfb :1 -screen 0 ‘1280x1024x16’ -ac &> /dev/null &” and “export DISPLAY=:1” and i would then be able to run “google-chrome –disable-gpu ‘http://www.google.com’ &”
    but i get then “[15334:15334:0402/162313.574900:ERROR:desktop_window_tree_host_x11.cc(1148)] Not implemented reached in virtual void views::DesktopWindowTreeHostX11::InitModalType(ui::ModalType)

    ]
    cause of that i asume if i solve the problem that protractor will find the right browser i will get anyway an error like above….

    if anybody could help this would be highly appreciated!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *