digg_de's picture

Hi,

has anyone experiences to get SeleniumHQ or Watir running on a Turnkey Lamp?

I just install ruby and ruby-dev and the watir-webdriver or selenium-webdriver. But it is not easy the get an inspector like firefox or chrome running on the lamp, because there is no X.

Has anyone an idea to get it running.

Thanks!!!

Forum: 
Jeremy Davis's picture

I haven't personally had any experience with Selenium (at all). However IIRC John Carver (Dude4Linux - TKL or GitHub) has played with it. I'm sure that he has discussed it somewhere (perhaps here on the forums or on GitHub in our tracker perhaps?) but I can't find it right now sorry...

IIRC there is a way to run it headlessly using headless webkit and/or something like PhantomJS. Actually a quick google bought up this page which looks relevant?!

digg_de's picture

I'm now testing selenium or watir with the headless extension (https://github.com/leonid-shevtsov/headless). It works fine on ubuntu. But i will integrated in the turnkey lamp, but there are some difficulties to get firefox running.

Thanks for help!

 

digg_de's picture

Here a summary to get watir working on turnkey lamp:

Install Firefox:

echo -e "\ndeb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main" | tee -a /etc/apt/sources.list.d/sources.list > /dev/null
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com C1289A29
apt-get update
apt-get install libgtk-3-0
apt-get install firefox-mozilla-build

Download and install geckodriver from here: https://github.com/mozilla/geckodriver/releases

Install Watir:

apt-get install ruby ruby-dev
gem install watir

Install headless:

apt-get install xvfb
gem install headless

Now you can use firefox for headless web testing with ruby like this:

require "rubygems"
require "headless"
require "watir"

# start firefox headless
headless = Headless.new
headless.start

browser = Watir::Browser.new :firefox
browser.goto "http://www.google.de"
html = browser.html

...

headless.destroy

This is working fine. I'm now trying to get it workking with google chrome ...

Jeremy Davis's picture

This looks like others will find it of interest! Good work. :)
digg_de's picture

I found now a way to use chrome/chromium for web testing.

Install chrome:

sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
apt-get update
apt-get install google-chrome-stable

Install chromium:

apt-get install chromium

You need both google-chrome and chromium. Google-chrome is not running, but is neccessary for the gnomedriver for watir. Chromium is running with parameter --no-sandbox:

chromium --no-sandbox

Download and install chromedriver from here: https://sites.google.com/a/chromium.org/chromedriver/

Install watir and headless.

Now you can use chrome for headless web testing (with disabled image download) with ruby like this:

require "rubygems"
require "headless"
require "watir"

# start chrome headless
headless = Headless.new
headless.start

# chrome disable load images
profile = Selenium::WebDriver::Chrome::Profile.new
profile['webkit.webprefs.loads_images_automatically'] = false

# start Browser
browser = Watir::Browser.new :chrome, :profile => profile, :switches => %w[--no-sandbox]
browser.goto "http://www.google.de"
html = browser.html

...

headless.destroy

Works fine ... and it's quite faster than firefox ...

Add new comment