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 .
1 | sudo aptitude install Xvfb |
Under Fedora the same can be achieve using command .
1 | sudo yum install xorg-x11-server-Xvfb |
For more on Xvfb package check your distribution provider .
Now start the Xvfb .
1 | 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 .
1 | 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 .
1 | sudo gem install selenium-webdriver |
Installation should work with any possible errors .
Now start your irb console .
1 2 3 4 5 |
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 .
1 | 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