Not that I really work with testing anymore, it still interest me. Well at least getting it more and more automated.
So getting Selenium 2.0 running on my windows laptop sounded like a good summer activity.
In fairness the people responsible for both Selenium 2.0 and selenium-webdriver (which is the ruby frontend, packaged as a ruby gem) did a fantastic job.
You need following installed to get it working:
Firefox (or else you can change the example code to use IE or Chrome etc.)
Ruby 1.9
(Selenium 2.0)
And a few more stuff detailed below.
- I installed first ruby 1.8.7 and the ruby 1.9.1 from the one-click installers.
- Then I went to the SeleniumHQ and specifically they're Webdriver page.
- Downloaded the complete package (selenium-server-2.0a5.zip) from the downloads page.
- Unpacked it and added that directory to the CLASSPATH environment variable (I used C:\selenium-2.0a5).
- Fired up a cmd prompt and installed the selenium-webdriver gem (gem install selenium-webdriver).
- Navigated to the ruby bindings webpage for the WebDriver API => http://code.google.com/p/selenium/wiki/RubyBindings
- Fired up gvim (feel free to use your favorite editor here!)
- Copy and pasted they're first example and it failed horrible. (Note that on some systems you will need 'require "rubygems"', best is to always use it). Save as google_test.rb
- Googled the problem "msvcrt-ruby18.dll selenium-webdriver", found a related watir problem => http://code.google.com/p/selenium/issues/detail?id=583
- Installed the devkit from rubyinstaller.org, devkit is available for download on this page => http://rubyinstaller.org/downloads/
- unpacked the contents into my ruby 1.9 directory (I use C:\Ruby191)
- fired up the cmd again and ran
gem uninstall win32-api
gem install win32-api --platform=ruby
as detailed in the watir fix - Then "ruby google_test.rb" in the cmd and everything worked as intended!
Hey -
ReplyDeleteThis is great information. I'm having problems with my spec to continue through the webdriver methods. It currently opens a Firefox 5.0 browser window, but it does not proceed to the webdriver.get method. Have you seen this problem before.
Here is what my code looks like
require 'rubygems'
require 'rspec'
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get "http://google.com"
Any help would be appreciated.
Thanks!
Here is the example that I used. Been a few months since I did this, well a year or so. Notice that I do not use the "get" but the "navigate" method.
ReplyDeleteNot sure if they have changed webdriver since then. Anyway here it is.
----
require "rspec"
require "selenium-webdriver"
describe "test" do
before(:all) do
@driver = Selenium::WebDriver.for :chrome
end
it "bla bla" do
@driver.navigate.to "http://google.com"
element = @driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts @driver.title[0..4].should eq("Hello")
end
after(:all) do
@driver.quit
end
end
---