Class: Ferrum::Dialog
- Inherits:
-
Object
- Object
- Ferrum::Dialog
- Defined in:
- lib/ferrum/dialog.rb
Overview
Represents a JavaScript dialog (alert, confirm, prompt or
beforeunload) shown by the page. Instances are yielded to blocks
registered with page.on(:dialog), and can be accepted (optionally with
a prompt's text) or dismissed.
Instance Attribute Summary collapse
-
#default_prompt ⇒ Object
readonly
Returns the value of attribute default_prompt.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#accept(prompt_text = nil) ⇒ Object
Accept dialog with given text or default prompt if applicable.
-
#dismiss ⇒ Object
Dismiss dialog.
-
#initialize(page, params) ⇒ Dialog
constructor
A new instance of Dialog.
-
#match?(pattern) ⇒ Boolean
Whether the dialog's message matches the given pattern.
Constructor Details
#initialize(page, params) ⇒ Dialog
Returns a new instance of Dialog.
13 14 15 16 17 |
# File 'lib/ferrum/dialog.rb', line 13 def initialize(page, params) @page = page = params["message"] @default_prompt = params["defaultPrompt"] end |
Instance Attribute Details
#default_prompt ⇒ Object (readonly)
Returns the value of attribute default_prompt.
11 12 13 |
# File 'lib/ferrum/dialog.rb', line 11 def default_prompt @default_prompt end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
11 12 13 |
# File 'lib/ferrum/dialog.rb', line 11 def end |
Instance Method Details
#accept(prompt_text = nil) ⇒ Object
Accept dialog with given text or default prompt if applicable
35 36 37 38 39 40 |
# File 'lib/ferrum/dialog.rb', line 35 def accept(prompt_text = nil) = { accept: true } response = prompt_text || default_prompt .merge!(promptText: response) if response @page.command("Page.handleJavaScriptDialog", slowmoable: true, **) end |
#dismiss ⇒ Object
Dismiss dialog.
56 57 58 |
# File 'lib/ferrum/dialog.rb', line 56 def dismiss @page.command("Page.handleJavaScriptDialog", slowmoable: true, accept: false) end |
#match?(pattern) ⇒ Boolean
Whether the dialog's message matches the given pattern.
68 69 70 71 72 |
# File 'lib/ferrum/dialog.rb', line 68 def match?(pattern) return .match?(pattern) if pattern.is_a?(Regexp) .include?(pattern.to_s) end |