Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ end
`Cuprite`-specific options are:

* options `Hash`
* `:raise_on_unhandled_modal` (Boolean) - When set to `false`, output a warning. When set to `true`, raise an exception
* `:url_blacklist` (Array) - array of regexes to match against requested URLs
* `:url_whitelist` (Array) - array of regexes to match against requested URLs

Expand Down
9 changes: 9 additions & 0 deletions lib/capybara/cuprite/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Browser < Ferrum::Browser
def initialize(options = nil)
super

@options.raise_on_unhandled_modal = options&.delete(:raise_on_unhandled_modal)
@options.url_blacklist = prepare_wildcards(options&.dig(:url_blacklist))
@options.url_whitelist = prepare_wildcards(options&.dig(:url_whitelist))

Expand Down Expand Up @@ -49,6 +50,14 @@ def resize(**options)
super
end

def raise_on_unhandled_modal
@options.raise_on_unhandled_modal
end

def raise_on_unhandled_modal=(value)
@options.raise_on_unhandled_modal = value
end

def url_whitelist
@options.url_whitelist
end
Expand Down
1 change: 1 addition & 0 deletions lib/capybara/cuprite/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def reset!
@paper_size = nil
browser.url_blacklist = @options[:url_blacklist]
browser.url_whitelist = @options[:url_whitelist]
browser.raise_on_unhandled_modal = @options.fetch(:raise_on_unhandled_modal, false)
browser.reset
@started = false
end
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/cuprite/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ferrum
class Browser
class Options
attr_writer :window_size
attr_accessor :url_blacklist, :url_whitelist
attr_accessor :url_blacklist, :url_whitelist, :raise_on_unhandled_modal

def reset_window_size
@window_size = @options[:window_size]
Expand Down
6 changes: 5 additions & 1 deletion lib/capybara/cuprite/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,14 @@ def prepare_page
response = @modal_response || params["defaultPrompt"]
else
with_text = params["message"] ? "with text `#{params['message']}` " : ""
warn "Modal window #{with_text}has been opened, but you didn't wrap " \
message =
"Modal window #{with_text}has been opened, but you didn't wrap " \
"your code into (`accept_prompt` | `dismiss_prompt` | " \
"`accept_confirm` | `dismiss_confirm` | `accept_alert`), " \
"accepting by default"

@options.raise_on_unhandled_modal ? raise(message) : warn(message)

options = { accept: true }
response = params["defaultPrompt"]
end
Expand Down
12 changes: 12 additions & 0 deletions spec/features/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,18 @@
expect(@session).to have_xpath("//a[@id='open-match' and @confirmed='true']")
end

it "configured to raise warning" do
@session.driver.browser.raise_on_unhandled_modal = true

@session.visit "/cuprite/with_js"

expect { @session.click_link("Open for match") }.to raise_error(
"Modal window with text `{T}ext \\w|th [reg.exp] (chara©+er$)?` has been opened, " \
"but you didn't wrap your code into (`accept_prompt` | `dismiss_prompt` | `accept_confirm` " \
"| `dismiss_confirm` | `accept_alert`), accepting by default"
)
end

it "matches on partial strings" do
@session.visit "/cuprite/with_js"
expect do
Expand Down
Loading