CSC/ECE 517 Fall 2014/ch1a 19 mx: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:
----
----


== Introduction==
= Introduction=
Watir('''W'''eb '''A'''pplication '''T'''est '''i'''n '''R'''uby), pronounced as 'water', is an automated test toolkit which uses the Ruby scripting language for automated tests to be developed and run against a web browser. <ref>http://www.httpwatch.com/rubywatir/</ref>It allows users to write tests that are easy to read and maintain, also simple and flexible. Watir was first developed by Bret Pettichord and Paul Rogers. It drives [http://en.wikipedia.org/wiki/Internet_Explorer Internet Explorer], [http://en.wikipedia.org/wiki/FirefoxMozilla Firefox|Firefox], [http://en.wikipedia.org/wiki/Chrome Google Chrome|Chrome], [http://en.wikipedia.org/wiki/Opera Opera (web browser)|Opera] and [http://en.wikipedia.org/wiki/Safari Safari (web browser)|Safari], and is available as a [http://en.wikipedia.org/wiki/RubyGems RubyGems] gem, <ref>http://en.wikipedia.org/wiki/Watir</ref> which is a free, open source Ruby library that  can test web applications written in any language<ref>https://rubygems.org/gems/watir-classic</ref> and drive a web browser the same way an end user would. It clicks links, fills in forms, presses buttons. Watir can also check results, such as whether expected text appears on the page or not, or whether a control is enabled. <ref>http://watir.com/</ref>
Watir('''W'''eb '''A'''pplication '''T'''est '''i'''n '''R'''uby), pronounced as 'water', is an automated test toolkit which uses the Ruby scripting language for automated tests to be developed and run against a web browser. <ref>http://www.httpwatch.com/rubywatir/</ref>It allows users to write tests that are easy to read and maintain, also simple and flexible. Watir was first developed by Bret Pettichord and Paul Rogers. It drives [http://en.wikipedia.org/wiki/Internet_Explorer Internet Explorer], [http://en.wikipedia.org/wiki/FirefoxMozilla Firefox|Firefox], [http://en.wikipedia.org/wiki/Chrome Google Chrome|Chrome], [http://en.wikipedia.org/wiki/Opera Opera (web browser)|Opera] and [http://en.wikipedia.org/wiki/Safari Safari (web browser)|Safari], and is available as a [http://en.wikipedia.org/wiki/RubyGems RubyGems] gem, <ref>http://en.wikipedia.org/wiki/Watir</ref> which is a free, open source Ruby library that  can test web applications written in any language<ref>https://rubygems.org/gems/watir-classic</ref> and drive a web browser the same way an end user would. It clicks links, fills in forms, presses buttons. Watir can also check results, such as whether expected text appears on the page or not, or whether a control is enabled. <ref>http://watir.com/</ref>


Watir project consists of several smaller projects, including watir-classic, watir-webdriver and watirspec.
Watir project consists of several smaller projects, including watir-classic, watir-webdriver and watirspec.


=== Watir-classic ===
== Watir-classic ==
Watir-classic is a Watir driver for automating only Internet Explorer on Windows.<ref>https://github.com/watir/watir-classic</ref>
Watir-classic is a Watir driver for automating only Internet Explorer on Windows.<ref>https://github.com/watir/watir-classic</ref>


Line 16: Line 16:
Watir-classic is able to work on Internet Explorer 8, 9 and 10<ref>http://rubydoc.info/gems/watir-classic/3.7.0/frames</ref>, and is supported by Ruby 1.8.7, 1.9.3 and 2.0.0.
Watir-classic is able to work on Internet Explorer 8, 9 and 10<ref>http://rubydoc.info/gems/watir-classic/3.7.0/frames</ref>, and is supported by Ruby 1.8.7, 1.9.3 and 2.0.0.


=== Watir-webdriver===
== Watir-webdriver==
Watie-webdriver is an implementation built on WebDriver's Ruby bindings. It supports not only the Internet Explorer, but also namely Firefox, Chrome and Safari.<ref>https://github.com/watir/watir-webdriver</ref>
Watie-webdriver is an implementation built on WebDriver's Ruby bindings. It supports not only the Internet Explorer, but also namely Firefox, Chrome and Safari.<ref>https://github.com/watir/watir-webdriver</ref>


Line 23: Line 23:
  gem install watir-webdriver
  gem install watir-webdriver


=== Watirspec ===
== Watirspec ==
Watirspec combines best features of Watir [http://en.wikipedia.org/wiki/RSpec RSpec] and Ruby for browser-based functional testing.<ref>https://rubygems.org/gems/watirspec</ref>
Watirspec combines best features of Watir [http://en.wikipedia.org/wiki/RSpec RSpec] and Ruby for browser-based functional testing.<ref>https://rubygems.org/gems/watirspec</ref>


Line 30: Line 30:
  gem install watirspec
  gem install watirspec


== Overview ==
= Overview =




=== Web Application Testing ===
== Web Application Testing ==
[http://en.wikipedia.org/wiki/Web_testing Web testing] is a software testing that focuses on web applications. Complete testing of a web-based system before going live can help address issues before the system is revealed to the public. Issues such as the basic functionality of the site, the security of the web application, its accessibility to handicapped users and fully able users, as well as readiness for expected traffic and number of users and the ability to survive a massive spike in user traffic, both of which are related to load testing.<ref>http://en.wikipedia.org/wiki/Web_testing</ref>
[http://en.wikipedia.org/wiki/Web_testing Web testing] is a software testing that focuses on web applications. Complete testing of a web-based system before going live can help address issues before the system is revealed to the public. Issues such as the basic functionality of the site, the security of the web application, its accessibility to handicapped users and fully able users, as well as readiness for expected traffic and number of users and the ability to survive a massive spike in user traffic, both of which are related to load testing.<ref>http://en.wikipedia.org/wiki/Web_testing</ref>


Line 48: Line 48:
*Performance Testing: Test for web application performance, which should include both Web Load Testing and Web Stress Testing.
*Performance Testing: Test for web application performance, which should include both Web Load Testing and Web Stress Testing.


=== Ruby ===
== Ruby ==
Ruby is a dynamic, designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan, is a reflective, object-oriented, general-purpose programming language. Like other programming languages, Ruby gives you the power to connect to databases, read data files and spreadsheets, export XML, and structure your code as reusable libraries. Unlike other programming languages, Ruby is concise and often a joy to read.<ref>http://watir.com/</ref>
Ruby is a dynamic, designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan, is a reflective, object-oriented, general-purpose programming language. Like other programming languages, Ruby gives you the power to connect to databases, read data files and spreadsheets, export XML, and structure your code as reusable libraries. Unlike other programming languages, Ruby is concise and often a joy to read.<ref>http://watir.com/</ref>


Line 60: Line 60:
[http://www.starkdigital.net/ruby-programming See More Features.]
[http://www.starkdigital.net/ruby-programming See More Features.]


== Installation ==
= Installation =
=== Installing Behind an Authenticating [http://en.wikipedia.org/wiki/Proxy Proxy]===
== Installing Behind an Authenticating [http://en.wikipedia.org/wiki/Proxy Proxy]==
Watir drivers are packaged as gems, Ruby libraries that can be installed over the internet. If installing behind an authenticating proxy, first set the HTTP_PROXY environment variable:
Watir drivers are packaged as gems, Ruby libraries that can be installed over the internet. If installing behind an authenticating proxy, first set the HTTP_PROXY environment variable:


Line 72: Line 72:
  export http_proxy=http://username:password@your.proxy.com:80
  export http_proxy=http://username:password@your.proxy.com:80


=== Install Ruby on Linux ===
== Install Ruby on Linux ==
Use your relevant package manager to update or install Ruby with the following at a terminal window:
Use your relevant package manager to update or install Ruby with the following at a terminal window:


  sudo apt-get install ruby  # for Ubuntu / Debian users
  sudo apt-get install ruby  # for Ubuntu / Debian users
  sudo yum install ruby      # for Red Hat / Fedora users
  sudo yum install ruby      # for Red Hat / Fedora users
=== Update RubyGems on Linux ===
== Update RubyGems on Linux ==
Make sure you have the latest rubygems version 1.3.7 or above installed. Use your relevant package manager to install the latest version with the following at a terminal window:
Make sure you have the latest rubygems version 1.3.7 or above installed. Use your relevant package manager to install the latest version with the following at a terminal window:


Line 83: Line 83:
  sudo yum install rubygems  # for Red Hat / Fedora users
  sudo yum install rubygems  # for Red Hat / Fedora users


=== Install a HTML Inspector ===
== Install a HTML Inspector ==
To use Watir effectively, you’ll need to be able to browse through the structure of your application’s HTML pages. These tools help you do that.
To use Watir effectively, you’ll need to be able to browse through the structure of your application’s HTML pages. These tools help you do that.


Line 89: Line 89:
*On Internet Explorer, use the IE Developer Toolbar
*On Internet Explorer, use the IE Developer Toolbar


=== Installing or Updating RubyGems ===
== Installing or Updating RubyGems ==
While updating RubyGems, or installing any of the gems, you can use the following additional flags:
While updating RubyGems, or installing any of the gems, you can use the following additional flags:


Line 99: Line 99:
  gem install watir --no-rdoc --no-ri
  gem install watir --no-rdoc --no-ri


== Make It Run ==
= Make It Run =
All examples are designed to work on the live Watir demo form: http://bit.ly/watir-example.
All examples are designed to work on the live Watir demo form: http://bit.ly/watir-example.


=== Run in .rb ===
== Run in .rb ==
First of all, let's see how to conduct the test in ruby on rails.<ref>http://watir.com/examples/</ref>
First of all, let's see how to conduct the test in ruby on rails.<ref>http://watir.com/examples/</ref>


Line 185: Line 185:
</pre>
</pre>


=== Run in Rspec ==
== Run in Rspec ==
RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD. The following code demonstrates using Watir and a basic RSpec example.<ref>http://watir.com/frameworks/</ref> [http://rspec.info/ More Info.]
RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD. The following code demonstrates using Watir and a basic RSpec example.<ref>http://watir.com/frameworks/</ref> [http://rspec.info/ More Info.]


Line 222: Line 222:
</pre>
</pre>


=== Run in Cucumber ===
== Run in Cucumber ==
Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid – all rolled into one format.<ref>http://watir.com/frameworks/</ref> [http://cukes.info/ More Info.]
Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid – all rolled into one format.<ref>http://watir.com/frameworks/</ref> [http://cukes.info/ More Info.]


1. Install
===Install===
<br>
<br>
<pre>
<pre>
Line 231: Line 231:
</pre>
</pre>


2. Example
===Example===
<br>
<br>
<pre>
<pre>
Line 270: Line 270:
</pre>
</pre>


== Comparison with Other Tools ==
= Comparison with Other Tools =


There are some other framworks will do similar work as watir does, for example, Cucmber, Capybara and RSpec. But in comparison, they have different features and are usually used in conjecture.
There are some other framworks will do similar work as watir does, for example, Cucmber, Capybara and RSpec. But in comparison, they have different features and are usually used in conjecture.
Line 282: Line 282:
RSpec helps you do the TDD(Test-Driven Development) part of the whole development (combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning), focusing on the documentation and design aspects of TDD. A combination of RSpec and Watir makes really readable test scripts.<ref>http://www.ibmwcs.com/2010/08/testing-with-rspec-cucumber-selenium.html</ref>
RSpec helps you do the TDD(Test-Driven Development) part of the whole development (combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning), focusing on the documentation and design aspects of TDD. A combination of RSpec and Watir makes really readable test scripts.<ref>http://www.ibmwcs.com/2010/08/testing-with-rspec-cucumber-selenium.html</ref>


== Reference ==
= Reference =
<references></references>
<references></references>

Revision as of 00:03, 20 September 2014

Watir


Introduction

Watir(Web Application Test in Ruby), pronounced as 'water', is an automated test toolkit which uses the Ruby scripting language for automated tests to be developed and run against a web browser. <ref>http://www.httpwatch.com/rubywatir/</ref>It allows users to write tests that are easy to read and maintain, also simple and flexible. Watir was first developed by Bret Pettichord and Paul Rogers. It drives Internet Explorer, Firefox|Firefox, Google Chrome|Chrome, Opera (web browser)|Opera and Safari (web browser)|Safari, and is available as a RubyGems gem, <ref>http://en.wikipedia.org/wiki/Watir</ref> which is a free, open source Ruby library that can test web applications written in any language<ref>https://rubygems.org/gems/watir-classic</ref> and drive a web browser the same way an end user would. It clicks links, fills in forms, presses buttons. Watir can also check results, such as whether expected text appears on the page or not, or whether a control is enabled. <ref>http://watir.com/</ref>

Watir project consists of several smaller projects, including watir-classic, watir-webdriver and watirspec.

Watir-classic

Watir-classic is a Watir driver for automating only Internet Explorer on Windows.<ref>https://github.com/watir/watir-classic</ref>

Install the Gem:

gem install watir-classic

Watir-classic is able to work on Internet Explorer 8, 9 and 10<ref>http://rubydoc.info/gems/watir-classic/3.7.0/frames</ref>, and is supported by Ruby 1.8.7, 1.9.3 and 2.0.0.

Watir-webdriver

Watie-webdriver is an implementation built on WebDriver's Ruby bindings. It supports not only the Internet Explorer, but also namely Firefox, Chrome and Safari.<ref>https://github.com/watir/watir-webdriver</ref>

Install the Gem:<ref>https://rubygems.org/gems/watir-webdriver</ref>

gem install watir-webdriver

Watirspec

Watirspec combines best features of Watir RSpec and Ruby for browser-based functional testing.<ref>https://rubygems.org/gems/watirspec</ref>

Install the Gem:

gem install watirspec

Overview

Web Application Testing

Web testing is a software testing that focuses on web applications. Complete testing of a web-based system before going live can help address issues before the system is revealed to the public. Issues such as the basic functionality of the site, the security of the web application, its accessibility to handicapped users and fully able users, as well as readiness for expected traffic and number of users and the ability to survive a massive spike in user traffic, both of which are related to load testing.<ref>http://en.wikipedia.org/wiki/Web_testing</ref>

Web Testing Checklist:<ref>http://www.softwaretestinghelp.com/web-application-testing/</ref>

  • Functionality Testing: Test for all the links in web pages, database connection, forms used in the web pages for submitting or getting information from user, as well as Cookie testing.
  • Usability Testing: Test for navigation, contents and other user information for user help.
  • Interface Testing: Test for main interfaces, such as Web server, application server interface and Database server interface. Check whether all the interactions between these servers are executed properly or not.
  • Compatibility Testing: Test for the compatibility of your web site, which is a very critical testing aspect, including Browser compatibility, Operating system compatibility, Mobile browsing and Printing options compatibility.
  • Performance Testing: Test for web application performance, which should include both Web Load Testing and Web Stress Testing.

Ruby

Ruby is a dynamic, designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan, is a reflective, object-oriented, general-purpose programming language. Like other programming languages, Ruby gives you the power to connect to databases, read data files and spreadsheets, export XML, and structure your code as reusable libraries. Unlike other programming languages, Ruby is concise and often a joy to read.<ref>http://watir.com/</ref>

According to its authors, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.<ref>http://en.wikipedia.org/wiki/Ruby_(programming_language)</ref>

Several Features:<ref>http://www.starkdigital.net/ruby-programming</ref>

See More Features.

Installation

Installing Behind an Authenticating Proxy

Watir drivers are packaged as gems, Ruby libraries that can be installed over the internet. If installing behind an authenticating proxy, first set the HTTP_PROXY environment variable:

Windows:

set HTTP_PROXY=http://username:password@your.proxy.com:80

Linux:

export http_proxy=http://username:password@your.proxy.com:80

Install Ruby on Linux

Use your relevant package manager to update or install Ruby with the following at a terminal window:

sudo apt-get install ruby  # for Ubuntu / Debian users
sudo yum install ruby      # for Red Hat / Fedora users

Update RubyGems on Linux

Make sure you have the latest rubygems version 1.3.7 or above installed. Use your relevant package manager to install the latest version with the following at a terminal window:

sudo apt-get install rubygems # for Ubuntu / Debian users
sudo yum install rubygems  # for Red Hat / Fedora users

Install a HTML Inspector

To use Watir effectively, you’ll need to be able to browse through the structure of your application’s HTML pages. These tools help you do that.

  • On Firefox, use Firebug
  • On Internet Explorer, use the IE Developer Toolbar

Installing or Updating RubyGems

While updating RubyGems, or installing any of the gems, you can use the following additional flags:

--no-rdoc --no-ri

For example:

gem update --system --no-rdoc --no-ri
gem install watir --no-rdoc --no-ri

Make It Run

All examples are designed to work on the live Watir demo form: http://bit.ly/watir-example.

Run in .rb

First of all, let's see how to conduct the test in ruby on rails.<ref>http://watir.com/examples/</ref>

  • You can require Ruby Watir gem first via the -rubygems command line option or by using the RUBYOPT environment variable. You can also require it manually in your script:
require 'rubygems'
  • Including Watir gem to drive Internet Explorer on Windows
require 'watir'
  • Including Watir-WebDriver gem to drive Firefox/Chrome on Windows/Mac/Linux
require 'watir-webdriver'
  • Starting a new browser & and going to our site
browser = Watir::Browser.new
browser.goto 'http://bit.ly/watir-example'
  • Setting a text field

browser.text_field(:name => 'entry.0.single').set 'Watir'
  • Setting a multi-line text box

text-box1.png

browser.text_field(:name => 'entry.1.single').set "I come here from Australia. \n The weather is great here."
  • Setting and clearing a radio button

browser.radio(:value => 'Watir').set
browser.radio(:value => 'Watir').clear
  • Setting and clearing check boxes

browser.checkbox(:value => 'Ruby').set
browser.checkbox(:value => 'Python').set
browser.checkbox(:value => 'Python').clear
  • Clearing, getting and selecting selection list values

browser.select_list(:name => 'entry.6.single').clear
puts browser.select_list(:name => 'entry.6.single').options
browser.select_list(:name => 'entry.6.single').select 'Chrome'
  • Clicking a button

browser.button(:name => 'submit').click
  • Checking for text in a page
puts browser.text.include? 'Your response has been recorded.'
  • Checking the title of a page
puts browser.title == 'Thanks!'

Run in Rspec

RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD. The following code demonstrates using Watir and a basic RSpec example.<ref>http://watir.com/frameworks/</ref> More Info.

1. Install

gem install rspec

2. Example

rspec test_spec.rb

will execute the following rspec example:

test_spec.rb

require "rubygems"
require "rspec"
require "watir-webdriver"
 
describe "google.com" do
  let(:browser) { @browser ||= Watir::Browser.new :firefox } 
  before { browser.goto "http://google.com" } 
  after { browser.close }
 
  it "should search for watir" do
    browser.text_field(:name => "q").set "watir"
    browser.button.click 
    browser.div(:id => "resultStats").wait_until_present
    browser.title.should == "watir - Google Search"
  end
end

Run in Cucumber

Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid – all rolled into one format.<ref>http://watir.com/frameworks/</ref> More Info.

Install


gem install cucumber

Example


cucumber features

will execute the following cucumber feature: features/example.feature

Feature: Search In order to use Google users must be able to search for content 
Scenario: Search for a term
Given I have entered "watir" into the query
When I click "search"
Then I should see some results

features/step_definitions/example_steps.rb

require "watir-webdriver"
require "rspec/expectations"
 
Given /^I have entered "([^"]*)" into the query$/ do |term|
  @browser ||= Watir::Browser.new :firefox
  @browser.goto "google.com"
  @browser.text_field(:name => "q").set term
end
 
When /^I click "([^"]*)"$/ do |button_name|
  @browser.button.click
end
 
Then /^I should see some results$/ do
  @browser.div(:id => "resultStats").wait_until_present
  @browser.div(:id => "resultStats").should exist 
  @browser.close
end

Comparison with Other Tools

There are some other framworks will do similar work as watir does, for example, Cucmber, Capybara and RSpec. But in comparison, they have different features and are usually used in conjecture.

Put simply, Watir is a browser driver. Lightweight and simple to use, Watir excels at automating modern browsers. Built in Ruby, it does not have an IDE of it's own, but it works well with other testing frameworks and solutions in the Ruby ecosystem.

Cucumber lets software development teams describe how software should behave in plain english, it is designed to allow you to execute automated integration tests. It is a tool for implementing Behavior Driven Development.It can work nicely in conjecture with Capybara and RSpec.

Capybara is a library written in the Ruby programming language which makes it easy to simulate how a user interacts with your application. It can talk with many different drivers which execute tests through the same clean and simple interface, including Selenium, Webkit or pure Ruby drivers.<ref>http://jnicklas.github.io/capybara/</ref>

RSpec helps you do the TDD(Test-Driven Development) part of the whole development (combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning), focusing on the documentation and design aspects of TDD. A combination of RSpec and Watir makes really readable test scripts.<ref>http://www.ibmwcs.com/2010/08/testing-with-rspec-cucumber-selenium.html</ref>

Reference

<references></references>