Selenium in headless with Xvfb under RUBY

Today I will demonstrate how did I manage to get Selenium (browser => “firefox”) running under headless state (click here to know more on this) .

Now we need Xvfb to accomplish this dirty task.

For Ubuntu the package is fairly straight forward just type in the command .

sudo aptitude install Xvfb

Under Fedora the same can be achieve using command .

sudo yum install xorg-x11-server-Xvfb

For more on Xvfb package  check your distribution provider .

Now start the Xvfb .

Xvfb -ac :99 &

The above command start the Xvfb in background with name Display=:99 .

Now to accomplish Selenium to work under headless state we need .

  1. Selenium RC Server [here] .
  2. Selenium Client Drivers .

more on both can be found here .

Start the Selenium RC Server .

java -jar selenium-server-standalone-2.0b2.jar &

The above command basically start the Selenium-RC-Server on  http://localhost:4444.

Now install selenium-webdriver [a.k.a Selenium Client Drivers] .
Note : Get your specific Selenium Client Driver based on language you prefer .

sudo gem install selenium-webdriver 

Installation should work with any possible errors .

Now start your irb console .

require "rubygems"
require "selenium-webdriver"
s1 = :url => "http://localhost:4444/wb/pub"
s1.get ""

Wolla lah that it mission accomplish. Selenium running under headless state .

Now there are couple of handy methods I want you to know before I say enough for this post .

Suppose you need to capture ScreenShoot of the visited page by Selenium .

To achieve this all you need to do is .

 s1.save_screenshoot "google.png" 

Ok! that it folks enough of me now.

I will be extensively working on Xvfb and Selenium in upcoming time so except some more article on Xvfb and Selenium .

Hope that it help you in same way or other .

Viren Negi

4 comments On Selenium in headless with Xvfb under RUBY

Leave a reply:

Your email address will not be published.

Site Footer