Tuesday, 23 April 2013

Selenium web driver with Ruby

Selenium with Ruby I just trying the selenium automation testing with ruby and it is very simple. Below is my simple selenium ruby code which open goole.com website in a browser and search by key "Selenium with ruby".

 Install the selenium gem
        gem install selenium-webdriver

 create ruby file with name "seleniumruby.rb" 

use selenium-webdriver by adding 
        require 'selenium-webdriver' 

 create object for firefox browser 
        browser = Selenium::WebDriver.for(:firefox) 

Open google.com in browser using browser object 
        browser.get('http://www.google.com') 

 get search input box object by using ID which you get by help of firebug in browser 
        input_box = browser.find_element(:id, "gbqfq") 

Pass key values to search text 
         input_box.send_keys('anand muranal') 

 Get button object using id of button 
         button = browser.find_element(:id, 'gbqfb') 

click the search button using button object 
         button.click 

 finally close the browser browser.quit Run the ruby file in console 
         ruby seleniumruby.rb 


 seleniumruby.rb
require 'selenium-webdriver' 
browser = Selenium::WebDriver.for(:firefox) 
browser.get('http://www.google.com') 
input_box = browser.find_element(:id, "gbqfq") 
input_box.send_keys('Selenium with ruby') 
button = browser.find_element(:id, 'gbqfb') 
button.click 
browser.quit

No comments:

Post a Comment