Sunday, 11 August 2013

How to Configure Selenium Webdriver with Ruby



Configure Selenium Webdriver With Ruby

Step 1 :  Download Ruby from http://www.ruby-lang.org/en/downloads/




Step 2: Install Ruby

Step 3: Verify Ruby Version

Open Start->Interactive Ruby

Write command RUBY_VERSION


Step 4: Download Selenium- Webdriver gem from http://rubygems.org/gems/selenium-webdriver

Step 5 :Install Selenium Webdriver Gem :

1.Open Start->cmd
2. Navigate to folder where gem is downloaded using cd
(Example cd c:\Users\Downloads)
3. Write command   gem install selenium-Webdriver


Step 5: Execute Webdriver script in Ruby

There are different ways to execute script

1. Write ruby code in notepad and save it with .rb extension and Run from Command Line

Steps:

-Paste following code in notepad and save as “Test.rb”


require "selenium-webdriver"

driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://bing.com"

element = driver.find_element(:id, "sb_form_q")
element.send_keys "Test Automation!"
driver.find_element(:id, "sb_form_go").click

puts "Test Completed"

puts driver.title

driver.quit


-Open Start->cmd

-Navigate to folder where .ruby file is installed

-Write ruby Test.rb


2.  Open Start->Interactive Ruby

Paste following code in ‘interactive Ruby’ Window


Note: for Ruby Scripting many tools are available like RDE, Ruby IDE etc.
Also Eclipse can be used for Ruby Scripting by adding some plug-ins.






No comments:

Post a Comment