Automating ‘Auto Complete’ text field using Watir-WebDriver
February 9, 2012
Requirement:
1. Navigate to Google.com
require 'rubygems'
require 'watir-webdriver'
browser=Watir::Browser.new :ie
browser.goto("google.com")
browser.text_field(:name,"q").set("Ravee")
sleep 3
auto_content=browser.table(:class,'gssb_m').trs
auto_content.each do |g|
if g.text.downcase == "raveendran"
g.click
sleep 3
break
end
end
RSpec + Watir WebDriver
January 19, 2012
Installation:
1. Install Ruby
2. CMD>gem install watir-webdriver
3. CMD>gem install rspec
Code:
google_search.rb
require 'rubygems'
require 'watir-webdriver'
class Google
def search(browser,term,result)
if browser.downcase=="ie"
br= :ie
elsif browser.downcase=="ff"
br= :ff
elsif browser.downcase=="chrome"
br= :chrome
else
br= :ie
end
$ie=Watir::Browser.new br
$ie.goto("http://google.com")
$ie.text_field(:name,'q').set(term)
sleep 3
$ie.button(:name,'btnG').click
sleep 3
$result=$ie.text.downcase.include?(result)
$ie.close
end
end
googleSearch_spec.rb
require 'rubygems'
require 'rspec'
require 'google_search'
describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Raveendran","ruby")
$result.should eq(true)
end
end
describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Raveendran","wordpress")
$result.should eq(true)
end
end
describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Watir, Selenium,Cucumber highline","raveendran")
$result.should eq(true)
end
end
describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Ruby highline","raveendran")
$result.should eq(true)
end
end
RUN THE RSPEC code:
1. Navigate to the folder where files available
>rspec googleSearch_spec.rb
OUTPUT:
It will launch Chrome browser and will execute the test cases. Finally You will get the output like,
Started ChromeDriver
port=4113
version=14.0.836.0
.Started ChromeDriver
port=4164
version=14.0.836.0
.Started ChromeDriver
port=4218
version=14.0.836.0
.Started ChromeDriver
port=4260
version=14.0.836.0
.
Finished in 77.28 seconds
4 examples, 0 failures
Watir WebDriver — Handling New Window
December 1, 2011
Situation:
1. You are in Parent Page.
2. Clicking link “Open” in Parent page.
3. It opens new window
4. You need to do actions there and come back to your parent window
Solution:
To Click the Link
require 'rubygems'
require 'watir-webdriver'
ff=Watir::Browser.new :ff
ff.goto("website.com")
ff.link(:text,'open').click
To handle the New window and performing some actions within that window,
ff.window(:title,/TITLE of the new window/i).use do
ff.send_keys('SampleText')
ff.button(:id,'insert').click
puts ff.title #returns the new window title
end
within a loop The button belongs to Newly opened window.
puts ff.title #returns the parent window title
Watir-webdriver cheatsheet
October 6, 2011
Getting Started Load the Watir Webdriver libraryrequire 'watir-webdriver'Open a browser (Ex: Internet Explorer)driver = Watir::Browser.new :ieGo to a specified URLdriver.goto 'http://www.orbitz.com/'Close the browserdriver.closeAccess an Element Type something in the Text box or text areadriver.text_field(:id,'airOrigin').set("MAA")To Clear the text from text fielddriver.text_field(:id,'airOrigin').clearButton To click the buttondriver.button(:id,'BUTTON_ID'').clickDrop down list To select the value from listdriver.select_list(:id,'airStartTime').select("1 am")To get the selected value from select fielddriver.select_list(:id,'airStartTime').valueCheck box To clik the check boxdriver.checkbox(:id,'airNonStopsPreferred').clickORdriver.checkbox(:id,'airNonStopsPreferred').setTo know the clicked? or not ?driver.checkbox(:id,'airNonStopsPreferred').set?Radio buttondriver.radio(:id,'htlChoice').clickTo verify Flights radio button selected or notdriver.radio(:id,'htlChoice').set?#if it returns TRUE then radio button already selected. To get the title of the webpageputs driver.titleReturn true if the specified text appears on the TAGputs driver.li(:class,'welcomeText').text.include("Welcome to Orbitz")To Click SPAN Elementsdriver.span(:text,'Find Flights').click
Watir and Cucumber
April 8, 2011
This is the best website to start cucumber with watir
For more details http://cukes.info
Watir Day 2011 Speakers Announced!
March 9, 2011
- Alister Scott: ThoughtWorks: The Elements of Cucumber Style
- Andreas Tolfsen: Opera Software: Watir 3 and the future
- Bret Pettichord: Convio: Opening & Host
- Hugh McGowan: Convio: Testing with Vision
- Marek Jastrzebski: Convio: Domain Specific Watir Page Objects
- Simon Stewart: Google: WebDriver
- Tim Koopmans: Altentee: WatirGrid
- Željko Filipin: WA Research: Adventures in promoting Watir
Watir — Integration with Fitnesse
October 20, 2010
Fitnesse –Open source Test managment and acceptance testing tool
Watir –Open source Functional testing tool
1. Download the JAR file from http://fitnesse.org/FrontPage.FitNesseDevelopment.DownLoad
2. Save it in d:\fitnesse\fitnesse.jar
3. Install Ruby
4. Install the gem fit with the help of command
>gem install fit
>gem install watir
5. Open Command Prompt and navigate to
D:\fitness>java -jar fitnesse.jar
FitNesse (v20100103) Started…
port: 80
root page: fitnesse.wiki.FileSystemPage at ./FitNesseRoot
logger: none
authenticator: fitnesse.authentication.PromiscuousAuthenticator
html page factory: fitnesse.html.HtmlPageFactory
page version expiration set to 14 days.
6. Open Browser and Navigate to “http://localhost/”
7. Click Properties or Navigate to “http://localhost/FrontPage?properties”
Change as per the snapshot and click Save Properties
Paste this code
!define COMMAND_PATTERN {ruby -I %p C:/ruby/lib/ruby/gems/1.8/gems/fit-1.2/bin/FitServer.rb}
!path D:/fit
!|mytest.Division|
|term|result_term|search?|
|Raveendran |music |true|
|Ruby |program |true|
9. In D:\ create folder named as “fit”
“Fit” folder should contain another one forlder named as “mytest”
“mytest” folder should contain “division.rb”
10.
Open division.rb file
paste the code
require ‘fit/column_fixture’
require ‘rubygems’
require ‘watir’
module Mytest
class Division < Fit::ColumnFixture
attr_accessor :term, :result_term
def search
@ie=Watir::IE.new
@ie.goto(“google.com”)
puts “Entering Term”
@ie.text_field(:name,’q').set(@term)
@ie.button(:name,’btnG’).click
@output = @ie.text.include?(@result_term)
@ie.close
return @output
end
end
end
11. Click “Test” in “http://localhost”
12. Fitnesse will provide the test result for your definitions. For ex, see the snapshot
Watir — Verifying the Current style Properties
September 27, 2010
require ‘rubygems’
require ‘watir’
ie=Watir::IE.new
ie.goto(“google.com”)
ie.image(:id,’logo’).document.currentstyle.height
#=> “190px”
ie.image(:id,’logo’).document.currentstyle.width
#=> “315px”
ie.image(:id,’logo’).document.currentstyle.fontfamily
#=> “arial,sans-serif”
ie.image(:id,’logo’).document.currentstyle.textalign
#=> “center”
ie.image(:id,’logo’).document.currentstyle.borderwidth
#=> “0px”
Watir — Priority for using attributes
September 24, 2010
Source:
<input id=”query1″ type=”text” autocomplete=”off” value=”" name=”query”/>
Code:
require ‘rubygems’
require ‘watir’
$ie=Watir::IE.new
$ie.maximize
$ie.goto(“http://search.aol.in/aol/webhome”)
$ie.text_field(:id,’query1′).value=”Raveendran”
Issue:
Change the last line of the code like this
$ie.text_field(:name,’query’).value=”Raveendran”
It is not working
. Rit ?
Solution:
So the first priority goes to the “ID” attirbute to access the input fields.


