Željko Filipin's Blog on Software and Testing

Test like you do not need the money.

Watir on WebDriver

with 28 comments

Jari Bakken just released Watir on WebDriver.

On Windows, install it with

gem install watir-webdriver

and use it with

require "rubygems" # optional
require "watir-webdriver"
browser = Watir::Browser.new(:firefox)

Supported browsers are Internet Explorer (:ie, :internet_explorer), Firefox (:ff, :firefox), Chrome (:chrome) and RemoteWebDriver Server (:remote).

Update 1: as Steve suggested, I have tried it on RubyInstaller.

Install RubyInstaller, DevKit and all required gems and it just works!

gem install watir-webdriver
gem install win32-process

Update 2: It works on Mac.

My Mac came with Ruby and RubyGems installed, so it was just:

sudo gem install watir-webdriver

Update 3: It works on Ubuntu Linux.

My Ubuntu did not have Ruby and RubyGems installed.

Install Ruby with:

sudo apt-get install ruby-full

You can install RubyGems with:

sudo apt-get install rubygems

but Jari said it would be better to install it from source. Downland the latest RubyGems tgz or zip file (rubygems-1.3.5.tgz and rubygems-1.3.5.zip at the moment), extract it, open Terminal in extracted folder and run:

sudo ruby setup.rb

Install watir-webdriver:

sudo gem1.8 install watir-webdriver

Update 4: watir-webdriver is no longer prerelase gem, so installation is simpler.

Written by Željko Filipin

January 12th, 2010 at 6:03 pm

Posted in Watir

28 Responses to 'Watir on WebDriver'

Subscribe to comments with RSS or TrackBack to 'Watir on WebDriver'.

  1. If you really want to live on the edge, how about trying it with RubyInstaller 1.8.6 [mingw32]?

    skim

    13 Jan 10 at 7:58 pm

  2. Steve, you are always full of good ideas. :) Will try tomorrow.

    Željko Filipin

    13 Jan 10 at 11:26 pm

  3. What does your gem list look like for 1.8.6 [i386-mingw32]? I tried running a simple script, but it’s failing on loading watir-webdriver (it can’t find it).

    I installed the three gems you mentioned for RubyInstaller.

    skim

    14 Jan 10 at 9:16 pm

  4. >ruby -v
    ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]
    
    >gem list
    
    *** LOCAL GEMS ***
    
    ffi (0.5.4)
    json_pure (1.2.0)
    rake (0.8.7)
    selenium-webdriver (0.0.14)
    watir-webdriver (0.0.1.dev)
    win32-api (1.4.5)
    win32-process (0.6.2)
    windows-api (0.4.0)
    windows-pr (1.0.8)
    

    Željko Filipin

    15 Jan 10 at 2:29 pm

  5. Steve, maybe you need to require rubygems.

    Željko Filipin

    15 Jan 10 at 6:55 pm

  6. Hmmm weird. It worked, but why? I thought I read something against requiring rubygems.

    skim

    15 Jan 10 at 11:09 pm

  7. Really? As far as I know requiring rubygems can not do any harm. In some implementations rubygems is already required, so you do not have to do it yourself.

    Željko Filipin

    15 Jan 10 at 11:18 pm

  8. Here’s the response article that points to the original for requiring rubygems: http://blog.mmediasys.com/2009/12/30/to-require-or-not-require-rubygems-in-your-applications-or-libraries/

    skim

    16 Jan 10 at 11:12 pm

  9. I have read the article and posts linked from it, and if you do not want to require rubygems, fell free to use solutions provided there. :)

    Željko Filipin

    18 Jan 10 at 2:34 pm

  10. Yeah, I just need to figure out what it’s complaining about ;-)

    skim

    19 Jan 10 at 10:13 pm

  11. I got super excited about this, but realized that Watir::Browser.attach was not working. Too bad, because I need attach support in the web apps I work on.

    I found this selenium issue that appears to describe the problem – I guess this means it’s a WebDriver issue rather than a watir-webdriver issue? Hopefully it will get fixed eventually…

    http://code.google.com/p/selenium/issues/detail?id=18

    Anonymous

    22 Jan 10 at 6:54 pm

  12. Yes, as far as I remember, Jari said attach is not working because WebDriver does not support it yet.

    Željko Filipin

    22 Jan 10 at 7:06 pm

  13. [...] January 28, 2010, Alan Baird (<alan_baird>) and Jari Bakken (<jarib>) had a chat about watir-webdriver on #watir IRC channel at freenode.net. Published with permission. [14:29] <alan_baird> [...]

  14. What do you need to do to get the remote web driver server working?

    Alister Scott

    8 Apr 10 at 11:07 am

  15. Alister, I did not play with remote server. It would be the best to ask at Webdriver or Selenium lists.

  16. Hi Željko Filipin,

    Thanks for your help.
    Could work in chrome with the help of Webdriver:).

    Godwin

    21 Apr 10 at 7:54 am

  17. Godwin, I am glad I could help. :)

    Željko Filipin

    21 Apr 10 at 10:12 am

  18. I have followed the install instructions as above and verified that I have the gems for watir-webdriver & selenium-webdriver in my ruby folder.

    I am using
    require ‘rubygems’
    require ‘watir-webdriver’

    browser = Watir::Browser.new(:chrome)

    and I get the error message:
    C:/Ruby/lib/ruby/gems/1.8/gems/watir-webdriver-0.0.1.dev5/lib/watir-webdriver/exception.rb:8: superclass mismatch for class UnknownObjectException (TypeError)
    from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’
    from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require’
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in’
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require’
    from C:/Ruby/lib/ruby/gems/1.8/gems/watir-webdriver-0.0.1.dev5/lib/watir-webdriver.rb:6
    from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require’
    from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require’
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require’
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in’
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require’
    from test.rb:8

    any ideas?

    Stuart Alexander

    5 May 10 at 5:47 pm

  19. Stuart,

    This is not the best place for your question. Please take a look at these:

    http://watir.com/support/
    http://github.com/jarib/watir-webdriver/issues

    Željko Filipin

    6 May 10 at 1:53 pm

  20. If you have somewhere else in your code:
    require ‘watir’

    you will get a superclass mismatch.

    Try opening a new irb session and:
    require ‘watir-webdriver’

    That should work, if not you have a different problem

    Steve

    15 Jun 10 at 10:35 pm

  21. Thanks Steve, I have forwarded your comment to Stuart.

    Željko Filipin

    16 Jun 10 at 9:35 am

  22. [...] 7:15 – Zeljko’s blog post on Webdriver installation [...]

  23. [...] Explorer to work, I came across watir-webdriver. There’s a great guide for setting it up here. I managed to get it to run a google search in Chrome, however when it came to a Zoombu search it [...]

  24. Hi,

    I installed watir-webdriver gem.
    When i ran the script, i am getting an “Extension error” pop up and chrome browser opens indicating chromeDriver server started..

    But it is not navigating to the desired web page.

    Env:
    Windows xp
    ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

    Sample script which i ran:
    #require “rubygems”
    require “watir-webdriver”

    browser = Watir::Browser.new(:chrome)
    browser.goto “http://google.com”
    browser.text_field(:name, ‘q’).set “watir-webdriver”
    browser.button(:name, ‘btnG’).click

    Abhishek

    19 Jul 10 at 8:55 pm

  25. Hi Abhishek, I have no idea why your script does not work. If you want an answer you should post your question at webdriver, watir-webdriver or watir support forums. Let me know if you can not find them.

    Željko Filipin

    23 Jul 10 at 11:08 pm

  26. Hello,
    Could you tell me what code did you use to test the webdriver on safari on Mac.

    Thanks.

    JD

    2 Aug 10 at 9:44 pm

  27. JD, as far as I know Safari on Mac is not supported. You should ask here: http://seleniumhq.org/support/

    Željko Filipin

    3 Aug 10 at 9:54 am

Leave a Reply