Module: Capybara::Lightpanda::Browser::Modals

Included in:
Capybara::Lightpanda::Browser
Defined in:
lib/capybara/lightpanda/browser/modals.rb

Overview

JS dialog handling via Lightpanda’s LP.handleJavaScriptDialog pre-arm model (PR #2261): accept/dismiss are sent BEFORE the triggering action; Page.javascriptDialogOpening supplies the text.

Instance Method Summary collapse

Instance Method Details

#accept_modal(_type, text: nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/capybara/lightpanda/browser/modals.rb', line 33

def accept_modal(_type, text: nil)
  prepare_modals
  params = { accept: true }
  params[:promptText] = text if text
  page_command("LP.handleJavaScriptDialog", **params)
end

#dismiss_modal(_type) ⇒ Object



40
41
42
43
# File 'lib/capybara/lightpanda/browser/modals.rb', line 40

def dismiss_modal(_type)
  prepare_modals
  page_command("LP.handleJavaScriptDialog", accept: false)
end

#find_modal(type, text: nil, wait: options.timeout) ⇒ Object

‘type` is accepted for the error message only: like Selenium (where alert/confirm are indistinguishable) and Cuprite (whose dialog handler accepts whatever fires), we deliberately do NOT reject a dialog whose reported type differs from the one Capybara asked for. Real suites wrap `data-confirm` deletes in `accept_alert` (e.g. solidus admin) and expect it to work; only the message text is matched.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/capybara/lightpanda/browser/modals.rb', line 51

def find_modal(type, text: nil, wait: options.timeout)
  regexp = text.is_a?(Regexp) ? text : (text && Regexp.new(Regexp.escape(text.to_s)))
  last_seen_message = nil
  claimed = nil
  Utils::Wait.until(timeout: wait, interval: 0.05) do
    claimed = pop_modal_message(regexp)
    next true if claimed

    last_seen_message = peek_last_modal_message || last_seen_message
    false
  end
  claimed[:message]
rescue TimeoutError
  raise_modal_not_found(type, text, last_seen_message)
end