Google

WATIR On hands Learning

How to start?
1. Open "SciTE" ( Start > Programs > Ruby-186-25 > SciTE ). We are using this editor to Write / Run our watir scripts.
OR
Open notepad.(text editor)
2. The first line of script should be : require "watir". Where require is a keyword which specifies to load Library Files.
3. You should save scripts with ".rb" extension.

Simple Watir Example:
1. Open IE browser.
2. Navigate to http://google.com
3. Enter "http://thequalitytesting.blogspot.com"
4. Click on "Google Search"
5. Validate result page with some keyword.

Watir Script:
Save below script as "simple_watir_example.rb"

require 'watir'
include Watir
myurl="http://thequalitytesting.blogspot.com/" #setting variable
ie=IE.new # to open IE browser
ie.goto("http://google.com") #Navigate browser to URL
ie.text_field(:name, "q").set myurl
# Setting text field with variable
ie.button(:name, "btnG").click # Click on button
if ie.contains_text("WATIR Tutorial")
# validating keyword on search results page
puts "Passed : Tutorial found."
else
Puts "Failed : Tutorial not foung."
end
puts "End of the script"
#to print string on the console

Script Result:
>ruby simple_watir_example.rb
Passed : Tutorial found.
End of the script
>Exit code: 0

1 comment:

CesarMCSE said...

This script does not seem to work. :(