Module: Watir::AlertHelper

Included in:
Browser
Defined in:
lib/watir-webdriver/extensions/alerts.rb

Overview

Deprecated, use the new Alert API instead.

Module provided by optional require:

require "watir-webdriver/extensions/alerts"

Instance Method Summary collapse

Instance Method Details

#alert(&blk) ⇒ Object

Overwrite window.alert()

This method is provided by an optional require - API is subject to change.


19
20
21
22
23
24
# File 'lib/watir-webdriver/extensions/alerts.rb', line 19

def alert(&blk)
  warn 'AlertHelper is deprecated. Use the new Alert API instead (e.g. browser.alert.ok)'
  execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }"
  yield
  execute_script "return window.__lastWatirAlert"
end

#confirm(bool, &blk) ⇒ Object

Overwrite window.confirm()

This method is provided by an optional require - API is subject to change.


32
33
34
35
36
37
# File 'lib/watir-webdriver/extensions/alerts.rb', line 32

def confirm(bool, &blk)
  warn 'AlertHelper is deprecated. Use the new Alert API instead (e.g. browser.alert.ok)'
  execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!bool} }"
  yield
  execute_script "return window.__lastWatirConfirm"
end

#prompt(answer, &blk) ⇒ Object

Overwrite window.prompt()

This method is provided by an optional require - API is subject to change.


45
46
47
48
49
50
51
52
53
# File 'lib/watir-webdriver/extensions/alerts.rb', line 45

def prompt(answer, &blk)
  warn 'AlertHelper is deprecated. Use the new Alert API instead (e.g. browser.alert.ok)'
  execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{MultiJson.encode answer}; }"
  yield
  result = execute_script "return window.__lastWatirPrompt"

  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k)}
  result
end