6. Broswer Actions using WATIR ie.html # returns html content of the page. ie.text # returns text on the page. ie.status # returns status of the page. ie.title # returns the title of the page. ie.back # similar to clicking browser back button. 7. WATIR with Javascript functions
1. Single line commenting : Use # at start of the line.
Eg: #ie.link(:text=>/Inbox/,:index=>1 ).click
2. Multi line commenting : USe =begin at the start and =end at the end
Eg:
=begin
3. Wait Command : Sleep is the command used for wait while running the script.
Eg: Sleep 3
brow=Watir::IE.new #creating instance of IE and assigning to a variable
OR
require 'watir'
include Watir
brow=IE.new # include will load the module
ie.goto("http://thequalitytesting.blogspot.com")
OR
ie=Watir::IE.start("http://thequalitytesting.blogspot.com")
ie.maximize # to minimize.
ie.minimize # to maximize.
ie.bring_to_front # to bring the browser front in all windows.
$HIDE_IE = true # to hide the browser running.
Eg: a id="netAdvertisingPromoterLink" onclick="return false" href="#">Advertising Survey on Share Market.
ie.link(:id,"netAdvertisingPromoterLink").fire_event("onclick")
In Watir we can use "flash" method to highlight the objects on the page. This is used mainly to identity specific web element when we have many web elements of same type/name.
Eg:
require 'watir'
ie.link(:text,/^Beg/).flash
$ is the regex matches end of line.
brow.link(:text,/uide.$/).flash
. matches any character
.* will matches any string and any number of times.
/ (backward slash) is used to escape special characters.
Eg : \/^$.+*?()[]\{\},
matches either of two.
[] matches a range of characters.
Eg: [a-z0-9]
[^] matches a negation of range of characters.
Eg : [^A-Z]
?= matches positive lookahead
?! matches negative lookahead
WATIR Tutorial :Important Notes
ie.link(:text=>/Inbox/,:index=>1).click
ie.link(:text, "Draft").click
ie.link(:text, "Sent").click
=end
4. To Start an Internet Explorer
require "watir'
5. To Navigate specified URL
ie=Watir::IE.new
To execute javacript functionalites, in Watir "fire_event" should be used.
In above HTML code onclick is javascript functionality which can be executed using,
8. Highlighting Web Elements
ie=Watir::IE.start("http://thequalitytesting.blogspot.com/")
ie.link(:text,/Beginners Testing Guide/).flash
9. Regular Expression in WATIR
Regular Expressions also known as RegEx. They are mainly used to Search/Match elements by giving specific strings from the set of strings in the Search Pattern. These are also used to escape Characters/Strings.
^ is the regex matches start of line.
brow.link(:text,/B./).flash
Eg: ab
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment