Google Maps Example

Submitted by Jonathan Kohl

# Purpose: * to demonstrate that WATIR can "see" into frames where "View Source" doesn't work
#          * to demonstrate an assertion based on HTML tag content

require 'rubygems'
require 'watir'   # the controller
require 'test/unit'

class TC_google_maps < Test::Unit::TestCase

    def test_google_maps
  
        #variables
        testSite = "http://maps.google.com"

        #open a browser
        browser = Watir::Browser.new

        puts "going to maps.google.com"
        browser.goto(testSite)

        puts "getting map for Durango"
        browser.text_field(:name,"q").set("Durango,CO")
        browser.button(:index, 1).click
	
        puts "showing the HTML inside the frame, where View Source does not work:"
        puts " "
        puts browser.frame("vp").html
   
        puts "storing frames HTML into variable for lat/long test assertion"
        matchlat = '37.283248999999998'
        matchlong = '-107.869123'

        begin
            assert_match(matchlat,browser.frame("vp").html.to_s)
            puts("PASS latitude OK\n")
        rescue => e
            puts("FAIL Didn't find latitude")
        end
 
        begin
            assert_match(matchlong,browser.frame("vp").html.to_s)
            puts("PASS longitude OK\n")
        rescue => e
            puts("FAIL Didn't find longitude")
        end
        
        browser.close  
        
    end

end
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.