How to run Selenium headless Firefox in Ubuntu

December 23, 2014
by Inaam Hussain

This tutorial will show you how to run Selenium headless Firefox in Ubuntu.

What is selenium?
Selenium automates browsers. Primarily, it is used for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can be automated as well.

In other words although it is an automated web testing framework,it can also be used for purposes other than testing .When we run firefox on server it has no display to show data or content, so with the help of xvfb: ( X-Virtual Frame Buffer ) and Selenium server standalone we can create display virtually and use or extract data virtually. (Ex : Login and Extract data).

Below the points to follow for run Selenium headless Firefox in Ubuntu,

Install Java :

sudo apt-get install openjdk-7-jdk

Download selenium standalone server : Find latest selenium standalone version from http://www.seleniumhq.org/download/

wget http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar

Install/Update firefox :

  • Install : For installing new firefox

sudo apt-get install firefox

  • Update : For update firefox new version

sudo add-apt-repository ppa:ubuntu-mozilla-security/ppa

sudo apt-get update

sudo apt-get install firefox

Install xvfb : ( X-Virtual Frame Buffer )

sudo apt-get install xvfb

Start XVFB server :

sudo nohup Xvfb :40 -ac &

(instead of 40 any number & for verify check ‘.X40-lock’ which has been created inside /tmp folder. It will show up when we do (ls -a) list all the files)

export DISPLAY=:40

sudo su

nohup java -jar selenium-server-standalone-2.44.0.jar &

now script is ready to run on headless Firefox.

Hope this tutorial will help you to run script on headless firefox.

To know more on selenium visit http://www.seleniumhq.org/

About

Engineer. Blogger. I like to be updated on new upcoming emerging technologies.

Get notified on our new articles

Subscribe to get the latest on Node.js, Angular, Blockchain and more. We never spam!
First Name:
Email:

Leave a Comment