Another example i thought i would share. Again I tried to keep the code very
readable. This example should be enough to get anyone going. I'm currently
using this with a DB and storing the yaml in a file, it works great!
I'll let the code and comments speak for itself, it should be readable.
----------------
# Lets require all the basics
require 'watir'
require 'yaml'
include Watir
# Using a global IE just to keep things simply
$ie = IE.new()
class Translation
def generate_translation_string()
# Lets setup the hash to hold the data
localized_string_hash = Hash.new()
# Now lets populate the hash
# In my siutation this is done from a DB and each string has a
unique value
# for example GOOGLE_SEARCH_ENGLISH, and GOOGLE_SEARCH_FRENCH
# I left it english and french to keep it simple
localized_string_hash["english"] = "Google Search"
localized_string_hash["french"] = "Recherche Google"
# this sends back the hash as yaml
# I tend to generate this only when strings change and store a
copy of it in a file
localized_string_hash.to_yaml
end
end
class Google
# Gate keeper, call this first to make sure we are where we should be
def go()
$ie.goto('http://www.google.com')
wait_until(5){ $ie.text_field(:name,'q').exists? }
end
# the meat of it
def verify_title(compare_title)
if $ie.text_field(:name,'q').title == compare_title
puts 'Title Compare: Pass'
else
puts 'Title Compare: Fail'
end
end
end
# Setup our Google object
google = Google.new()
# Now setup our translation object
translation = Translation.new()
# Get the yaml translation string
yaml_string = translation.generate_translation_string()
# Lets look at it
# Its very simple!
puts yaml_string
# Load it into a new hash
new_hash = YAML::load( yaml_string )
# Navigate to Google
google.go()
# Now the magic
google.verify_title(new_hash["english"])
google.verify_title(new_hash["french"])
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general