Sha256: f951a730b2318a211177acd9fcbf273b97a42d501e73e6ae39592e0be83dd44e
Contents?: true
Size: 1.74 KB
Versions: 5
Compression:
Stored size: 1.74 KB
Contents
module Watir # # Module provided by optional require: # # require "watir-webdriver/extensions/alerts" # module AlertHelper # # Overwrite window.alert() # # This method is provided by an optional require - API is subject to change. # # @example # browser.alert do # browser.button(:value => "Alert").click # end #=> "the alert message" # def alert(&blk) execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }" yield execute_script "return window.__lastWatirAlert" end # # Overwrite window.confirm() # # This method is provided by an optional require - API is subject to change. # # @example # browser.confirm(true) do # browser.button(:value => "Confirm").click # end #=> "the confirm message" def confirm(bool, &blk) execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!bool} }" yield execute_script "return window.__lastWatirConfirm" end # # Overwrite window.prompt() # # This method is provided by an optional require - API is subject to change. # # @example # browser.prompt("hello") do # browser.button(:value => "Prompt").click # end #=> { :message => "foo", :default => "bar" } # def prompt(answer, &blk) execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default: value }; return #{answer.to_json}; }" yield result = execute_script "return window.__lastWatirPrompt" result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k)} result end end class Browser include AlertHelper end end
Version data entries
5 entries across 5 versions & 2 rubygems