Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Created January 26, 2010 16:20
Show Gist options
  • Save rtacconi/286963 to your computer and use it in GitHub Desktop.
Save rtacconi/286963 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../test_helper'
class PickaxeBookGooggleSearchTest < ActiveSupport::TestCase
include WatirOnRails
# Uncomment the following lines to specify a test server.
# WatirOnRails defaults to http://localhost:3000
#
# server "localhost"
# port 3001
# fixtures :foos, :bars
def test_pickaxe_google_search
test_site = 'http://www.google.com'
ie = open_browser
puts "Beginning of test: Google search."
puts " Step 1: go to the test site: " + test_site
ie.goto test_site
puts " Step 2: enter 'pickaxe' in the search text field."
ie.text_field(:name, "q").set "pickaxe" # "q" is the name of the search field
puts " Step 3: click the 'Google Search' button."
ie.button(:name, "btnG").click # "btnG" is the name of the Search button
puts " Expected Result:"
puts " A Google page with results should be shown. 'Programming Ruby' should be high on the list."
puts " Actual Result:"
if ie.text.include? "Programming Ruby"
puts " Test Passed. Found the test string: 'Programming Ruby'. Actual Results match Expected Results."
else
puts " Test Failed! Could not find: 'Programming Ruby'."
end
ie.link(:text, "Pickaxe - Wikipedia, the free encyclopedia").click
if ie.text.include? "From Wikipedia, the free encyclopedia"
puts "The browser is inside Wikipedia"
else
put "Error: could not reach Wikipedia web site"
end
if ie.text.include? "Some people make the distinction that a pickaxe has a head with a pointed end and a flat end, and a pick has both ends pointed, or only one end; but most people use the words to mean the same thing."
puts "Yes, I can read the first paragraph"
else
puts "Error: I cannot read the first paragraph"
end
puts "Since I am not in the Pickaxe book web site, I am going back to the previous visited page (back button)"
ie.back
puts "I am following the link for the Pickaxe book..."
ie.link(:text, "The Pragmatic Bookshelf | Programming Ruby").click
ie.image(:src, "http://assets2.pragprog.com/images/logo.gif?1264475979").exists?
puts "Yes! I am inside the pragprog web site."
puts "End of test: Google search."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment