Showing posts with label tools. Show all posts
Showing posts with label tools. Show all posts

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 

 



Canoo WebTest

Canoo WebTest is an open-source tool for testing web applications. It doesn't use real browsers, it validates HTML to comply with the specification. It also has support for testing PDF files, Excel sheets, Java applets and emails. Scripting languages are XML (Ant) or Groovy.

As WebTest scripts are Ant scripts, they are easy to integrate in continuous integration tools. Because WebTest is simply Java it can run everywhere. It is also fast as it doesn't have to load CSS and images and wait for page rendering. There is also a WebTest recorder available, with which you can record your first drafts of the tests. WebTest also has very good built-in reporting functionality.




One thing that can be seen as both good or not so good is that it forces developers to write good HTML, because scripts will fail if HTML doesn't comply with the specification. Javascript support is neither as good as in normal browsers.

If you don't care about running scripts in normal browsers and your application doesn't use much javascript, then this is a good tool for testing your web application.


Installation

 

  1. Install Java JDK version 5 or higher.
  2. Download latest version of WebTest from http://webtest.canoo.com and extract it. 
  3. Add WebTest bin folder to PATH.
  
How to run scripts


  1. Create a new project with command: webtest -f path\to\webtest\webtest.xml wt.createProject
  2. In the new project folder run the command: webtest

Example script

<?xml version="1.0"?>
<!DOCTYPE project SYSTEM "../dtd/Project.dtd">
<project default="test">
<target name="test"> 
 
  <webtest name="testing Google search">
  <invoke url="http://www.google.com" description="Go to Google"/>
  <setInputField name="q" value="WebTest" /> 
  <clickButton id="gbqfb" description="Click search"/>
  <verifyText text="Canoo WebTest" />
  </webtest
</target>
</project>


More information

 

   

Watir & Watir-webdriver

Watir is an open-source tool for automating web browsers. Watir supports only IE, but Watir-webdriver supports also Firefox, Chrome and Safari. Scripting language is Ruby.

Watir is a bit more mature, faster and stable than watir-webdriver. Watir is also always automatically waiting for the pages / components to fully load before continuing, not like Selenium or Watir-webdriver where you sometimes have to add extra code for that.

If you don't care about running scripts in different browsers or on different operating systems, then I would use Watir. If you want to run your scripts against different browsers or your application is having frames / iframes, then I would use Watir-webdriver.

Ruby is an excellent scripting language with a lot of existing gems for e.g. ssh, ftp, http and mysql connectivity. Watir doesn't have any in-built logging functionality, but using it together with Cucumber makes it an excellent tool / framework for testing web applications.

Watir is a tool developed by testers for testers.


Installation

 

  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. Download Ruby Devkit from http://www.rubyinstaller.org and extract it. In the extracted folder, run commands ruby dk.rb init and ruby dk.rb install to setup and install it.
  3. Install Watir gem with command: gem install watir
  4. Install Watir-webdriver gem with command: gem install watir-webdriver
 
Example script - Google search

 

require 'rubygems'
require 'watir-webdriver'

begin   
    browser = Watir::Browser.new(:firefox)
   
    puts "Go to google.com"
    browser.goto "http://www.google.com"

    puts "Search for Watir"
    browser.text_field(:name, "q").set "Watir"
    browser.button(:id, "gbqfb").click
   
    Watir::Wait.until { browser.text.include? 'Web Application Testing in Ruby' }
   
    browser.close

rescue
    puts "FAILED: " + $!.to_s
    browser.close
end

 
More information