Anyway to run my Watir-Webdriver tests Headless???

1,108 views
Skip to first unread message

Usman Hussain

unread,
Nov 4, 2010, 8:05:08 AM11/4/10
to webdriver
Hi Guys,

I was just wondering if anyone could give me a hand on this.
I would like to run my Watir-Webdriver tests headless (without a
browser) to speed up the time taken to run the tests.

Is there a way i can use what is already written and just get it to
run headless?
Or do i need to do something else.

I have a basic feature file (cucumber):
Feature: Testing of Google

Scenario: Testing testing
Given I have a browser
When I visit 'http://www.google.co.uk'
Then Enter in the search term 'GameSys'
And Click on the Search button

I have an env.rb file which looks like this:
require 'rubygems'
require 'webdriver'
require 'rspec'

def start_browser
@browser = Watir::Browser.new(:firefox)
end

After do
@browser.close
end

And my step_definitions file (code) looks like this:
Given /^I have a browser$/ do
start_browser
end

When /^I visit 'http:\/\/www\.google\.co.uk'$/ do
@browser.goto('http://www.google.co.uk')
end

Then /^Enter in the search term 'GameSys'$/ do
@browser.text_field(:class => 'lst', :title => 'Google
Search', :name => 'q').set 'GameSys'
end

Then /^Click on the Search button$/ do
@browser.button(:class => 'lsb', :value => 'Google Search', :name =>
'btnG').click
end

Any help would be much appreciated.

Kind Regards,
Usman Hussain

Jari Bakken

unread,
Nov 4, 2010, 9:29:46 AM11/4/10
to webd...@googlegroups.com
On Thu, Nov 4, 2010 at 1:05 PM, Usman Hussain <usmanh...@gmail.com> wrote:
> Hi Guys,
>
> I was just wondering if anyone could give me a hand on this.
> I would like to run my Watir-Webdriver tests headless (without a
> browser) to speed up the time taken to run the tests.
>

Check out my answer here:

http://stackoverflow.com/questions/3861871/can-i-use-watir-to-scrape-data-from-a-website-on-a-linux-server-without-monitor/3863321#3863321

Jari

Usman Hussain

unread,
Nov 4, 2010, 11:24:00 AM11/4/10
to webdriver
Cool... Ill take a look at it now.
cheers Jari

On Nov 4, 1:29 pm, Jari Bakken <jari.bak...@gmail.com> wrote:
> On Thu, Nov 4, 2010 at 1:05 PM, Usman Hussain <usmanhhuss...@gmail.com> wrote:
> > Hi Guys,
>
> > I was just wondering if anyone could give me a hand on this.
> > I would like to run my Watir-Webdriver tests headless (without a
> > browser) to speed up the time taken to run the tests.
>
> Check out my answer here:
>
> http://stackoverflow.com/questions/3861871/can-i-use-watir-to-scrape-...
>
> Jari

Usman Hussain

unread,
Nov 4, 2010, 12:44:53 PM11/4/10
to webdriver
Hey jari,

Ive seen the link and it says:
Use a real browser + a virtual X server (Xvfb). I'd recommend using
watir-webdriver's Firefox driver and the Headless gem for a simple way
to control this from Ruby.

ive searched google for xvfb... but im not quite getting this.

can you guide me or give me a starting point. Ive looked for examples
but havent found any real helpful ones out there...

Any help would be great.

Kind regards,
Usman Hussain

On Nov 4, 1:29 pm, Jari Bakken <jari.bak...@gmail.com> wrote:
> On Thu, Nov 4, 2010 at 1:05 PM, Usman Hussain <usmanhhuss...@gmail.com> wrote:
> > Hi Guys,
>
> > I was just wondering if anyone could give me a hand on this.
> > I would like to run my Watir-Webdriver tests headless (without a
> > browser) to speed up the time taken to run the tests.
>
> Check out my answer here:
>
> http://stackoverflow.com/questions/3861871/can-i-use-watir-to-scrape-...
>
> Jari

Jari Bakken

unread,
Nov 4, 2010, 12:57:09 PM11/4/10
to webd...@googlegroups.com
On Thu, Nov 4, 2010 at 5:44 PM, Usman Hussain <usmanh...@gmail.com> wrote:
> ive searched google for xvfb... but im not quite getting this.
>
> can you guide me or give me a starting point. Ive looked for examples
> but havent found any real helpful ones out there...
>
> Any help would be great.

There should be plenty of resources online to get you started. The
headless gem linked to from the SO post provides a nice Ruby wrapper,
assuming you have Xvfb installed (should be available in package
managers on all modern Linux distros) - check its README for example
usage:

https://github.com/leonid-shevtsov/headless/blob/master/README.md

If you're using Hudson for CI there's also an Xvfb/Xvnc plugin that
will start/stop the virtual display for you.

Usman Hussain

unread,
Nov 4, 2010, 1:33:13 PM11/4/10
to webdriver
Hey Jari,

I just realised that Xvfb is used on windows or linux.
Im running all my tests from a mac... any ideas how i can get
something for the mac that will make it work?

Kind regards,
Usman Hussain

On Nov 4, 4:57 pm, Jari Bakken <jari.bak...@gmail.com> wrote:

Jari Bakken

unread,
Nov 4, 2010, 1:54:09 PM11/4/10
to webd...@googlegroups.com
On Thu, Nov 4, 2010 at 6:33 PM, Usman Hussain <usmanh...@gmail.com> wrote:
>
> I just realised that Xvfb is used on windows or linux.
> Im running all my tests from a mac... any ideas how i can get
> something for the mac that will make it work?
>

You should be able to get Xvfb + Firefox working under X11 on OS X,
but I don't know what's needed. And I doubt any speed increase will be
significant enough to be worth the trouble.

Reply all
Reply to author
Forward
0 new messages