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 .
- Selenium RC Server [here] .
- 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 = Selenium::WebDriver::Remote.new :url => "http://localhost:4444/wb/pub" s1.get "http://railstech.com" s1.page_source
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 .
Thanks
Viren Negi
4 comments On Selenium in headless with Xvfb under RUBY
Great article!!. How can I integrate this with Rspec and capybara
Sorry never tried Selenium for integration testing ,h’mm might be a good candidate for future post . In case you manage to find it prior to me please share it across.
Thanks for jotting this stuff down, will be using it soon enough!
Dan
Just want share a thought on Ruby Interface for Xvfb “headless” checkout if it help you out
https://github.com/leonid-shevtsov/headless