Monday, August 27, 2012

Selenium Webdriver

Selenium Webdriver is an open-source tool for testing web applications. It supports IE, Firefox, Chrome, Opera and Safari browsers. It can run scripts locally or on a remote machine. Supported scripting languages are Java, C#, Python, Ruby, PHP, Perl ..

Selenium is probably the biggest web test automation tool. It is the core technology in many browser automation tools, APIs and frameworks. It doesn't have any built-in logging / reporting functionality, but using it together with e.g. Robot Framework, makes it an excellent web test automation tool.  

If you like to write scripts in Ruby, then I would pick Watir as the web test automation tool. Otherwise, Selenium is a very good choise.

Below I will describe how to install Selenium and write test scripts in Ruby. 



Installation (Ruby)


  1. Download Ruby installer from http://www.rubyinstaller.org and run it. During installation select Ruby to be added to PATH and to associate .rb files to this Ruby installation.
  2. Install Selenium Webdriver gem with command: gem install selenium-webdriver.

Example scripts

 

require 'rubygems'
require 'selenium-webdriver'

begin
  browser = Selenium::WebDriver.for :firefox
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
 
  puts "Go to google.com"
  browser.get "http://www.google.com"
  puts "Search for Selenium"
  element = browser.find_element(:name, "q")
  element.send_keys "Selenium"
  element.submit
  wait.until { browser.find_element(:tag_name, "body").text.include?( 'Web Browser Automation') }
 
  browser.quit
 
rescue
  browser.quit
end


More information 

 



No comments:

Post a Comment