Go to command prompt and type this:
ruby -e ‘require “watir”; puts Watir::IE::VERSION
You should get something like this:
1.5.1.1029
ruby -v
gem list – local or gem list
To Install type:
gem install watir-1[1].5.1.1145.gem Replace watir-1[1].5.1.1145 with the version you wish to install
To Uninstall:
gem uninstall watir
Go to Google and type the following:
site:rubyforge.org “[wtr-general]” javascript
Replace the word ‘javascript’ with the search term you are searching for
This will click the first link that is found on the page:
ie.link(:text, ‘Employees’).click
Use this syntax for the second (or more):
ie.link(:text⇒‘Employees’, index⇒2).click
This is how you can flash all radio buttons in a form.
ie.form(:index, 1).radios.each { |radio| radio.flash }
require ‘thread’
require ‘watir’
def test_google
ie = Watir::IE.start(’http://www.google.com‘)
ie.text_field(:name, “q”).set(”pickaxe”)
ie.button(:value, “Google Search”).click
end
Run the same test three times concurrently in separate browsers
threads = []
3.times do
threads « Thread.new {test_google}
end
threads.each {|x| x.join}
In this example 3 browser connection are open. Are these 3 browser connection open at same time or one after the another.
Per Bret Pettichord: Concurrent threads run in parallel.
1:#!/usr/bin/ruby -w
2:puts "Hello World!\n"
3:
4:# Print a variable
5:test = "human events"
6:puts test
7:
8:# Combining or concatenating two strings
9:puts "1: When in the course of " + test
10:
11:# Printing a value within a String. Interpolation like Perl
12:puts "2: When in the course of #{test}"
13:
14:# Create a value using a here docment
15:heredoc = <<END_OF_STRING
16:-------------------------------
17:Calling the test value again:
18:#{test}
19:End of the text
20:-------------------------------
21:END_OF_STRING
22:
23:puts heredoc
24:
require ‘watir/assertions’ | Method Examples |
|---|
assert(ie.contains_text(”text”))assert(ie.contains_text(/Hello Friends/i))puts (”Test passed”) |
def test_assertButtonassert($ie.button(:caption, “Click Me”).enabled?)end |
def test_assertLinkassert($ie.link(:text, “Click Me”).exists?)end |
def test_assertTextfieldassert($ie.text_field(;name, “field1”).exists?)end |
def test_assertRbuttonassert($ie.radio(:value, “radio button”).isSet?end |
def assertButtonverify($ie.button(:caption, “Click Me”).enabled?)end |
unittests directory of your watir installation.
(C:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.1.1145\unittests)
To get a concise list of _everything_ an array can do, try this from irb: <
any_old_array = [] puts any_old_array.methods
| root | parent | child | What is this file? |
|---|---|---|---|
| Readme.txt | This is where you describe your package. | ||
| Rakefile | The rakefile makes it easier to do tasks like run tests. | ||
| Setup.rb | |||
| bin/ | bin is where to put complete scripts that you run from the command line. | ||
| bin-skeleton | |||
| test/ | test is for tests. | ||
| test-skeleton | |||
| lib/ | lib is for all the other Ruby files in your project (ones that are required by a bin script or other Ruby file. | ||
| default-project.rb | |||
| default-project/ | |||
| lib-skeleton | |||
| third-party | |||
| s4t-utils.rb | |||
| s4t-utils.rb |
On organizing test cases using test::unit:
A. If you have the following methods in a testcase using test::unit →
def setup
def test_01
def test_02
def test_03
def teardown
They will execute in this order (every test method is wrapped with the ‘setup’ and ‘teardown’ methods)
def setup
def test_01
def teardown
def setup
def test_02
def teardown
def setup
def test_03
def teardown
You’ll want to write your testcases such that you are not launching your ie browser 66x or 180x, etc... use less methods and more assertions within your methods to prevent this...
B. Keep your test cases organized by objective or method of testing.
For example: If it’s a simple navigation test,
1. Keep all the sidebar navigation elements testing in one case.
2. & the main ‘div’ elements in another.
| Object | Object Identifiers | Common Methods |
|---|---|---|
| Button | :id | .attach |
| Radio | :name | .back |
| Checkbox | :value | .bring_to_front |
| Textfield | :index | .checked? |
| Hidden | :title | .clear |
| SelectList | :url | .click |
| Label | :class | .close |
| Span | :text | .contains_text |
| Div | :beforeText | .each |
| P | :afterText | .enabled? |
| Link | .exists? | |
| Table | .flash | |
| Image | .focus | |
| .front? | ||
| .isSet? | ||
| .new | ||
| .readonly? | ||
| .screen_capture | ||
| .select | ||
| .set | ||
| .show_all_objects | ||
| .to_a | ||
| .to_s | ||
| .wait | ||
| .wait_for_browser |