Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Selenium WebDriver working with selenium-webdriver gem

Surprisingly, I couldn't find a first step guide on how to setup Selenium WebDriver working with selenium-webdriver gem through google university. I suppose the gem needs to know where I store all those jar files to get started. How can I configure this?

like image 381
yiwen Avatar asked May 08 '10 20:05

yiwen


People also ask

Can we use Ruby with selenium?

You can use Selenium WebDriver APIs to devise test code using Selenium-supported languages like Ruby, Java, JavaScript, C#, and Python. Selenium and Ruby can be used together, and one of the best ways to do it is through using a gem called selenium-webdriver.


1 Answers

First you have to install the gem selenium-webdriver:

gem install selenium-webdriver

Then you can start your ruby program:

#You need to require the gem "selenium-driver"
require "selenium-webdriver" 

#... see webdriver ruby api docs here: http://selenium.googlecode.com/svn/trunk/docs/api/rb/_index.html
#... Most usefull classes are Driver and Element, check them out for a good start
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit

You can find more info:

about webdriver and ruby (all said above was an attempt to summarize it)

about the Ruby webdriver API

As you can see at a glance, the Webdriver API by itself has a different "style" of normal selenium-ruby programs... If you want to use webdriver and still continue to program with the Selenium-API, you should probably chech the Selenium2.0 Remote Server, as it seems that it will use Webdriver in a transparent way, while still mantaining the same known Selenium ruby Api

If I'm wrong with some part of the info, please correct me and we will all together make it clearer :)

PD: Best found info about relationship between Selenium and Webdriver was this blog post

like image 116
zipizap Avatar answered Oct 14 '22 05:10

zipizap