Skip to content

Instantly share code, notes, and snippets.

@hemanth

hemanth/watir.rb Secret

Created December 4, 2012 04:34
Show Gist options
  • Save hemanth/4ffa1f0c197d4ef572b0 to your computer and use it in GitHub Desktop.
Save hemanth/4ffa1f0c197d4ef572b0 to your computer and use it in GitHub Desktop.
Override water
class Watir::IE
# Use alias chaining to add some code to the Watir::IE.attach method.
# We need to make it click the insecure certificate warning override link
# if the link appears in the attached-to window. IE8 on Vista shows the
# warning for popups even if you already accepted the cert in the parent
# window.
#
# This code looks a little unusual, since attach is a class method, and
# aliasing a class method (instead of an instance method) requires this
# "class <<self" trick.
class <<self
# Alias the Watir::IE.attach method as Watir::IE.original_attach.
alias original_attach attach
# Re-define the attach method. No leading "self." is required to make
# this a class method, since I believe the "class <<self" bit above
# ensures that any method defined in its scope is a class method.
def attach(how, what)
# If the caller wants to attach by title, we have to first click the
# cert warning before the real title of the window will show up.
# The title will be "Certificate Error" until the warning is gone.
if (how == :title)
begin
cert_warning = original_attach(:title, /^Certificate Error/)
cert_warning.click_ssl_warning_override_link()
puts "Found and clicked cert warning link in attachable window..."
rescue Watir::Exception::NoMatchingWindowFoundException
puts "No cert warning seen in attachable browser. Moving along..."
end
end
ie = original_attach(how, what)
# Handle SSL warning message if it appears in the window
ie.click_ssl_warning_override_link()
return ie
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment