Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased](https://github.com/rubycdp/cuprite/compare/v0.20...main) ##

### Added
- `:url_blocklist` and `:url_allowlist` driver options as aliases for `:url_blacklist` and `:url_whitelist` [#330]

### Changed
- `Driver#current_url` and `Driver#title` read Ferrum's `url` and `title` of the window, not `current_url` and
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ end
that triggered the dialog (a click, `visit`, `evaluate_script`, ...), since a JS dialog blocks the page until
answered, so that action's own command is what was waiting. A dialog fired with nothing in flight (e.g. a bare JS
timer) only surfaces on whatever command runs next.
* `:url_blacklist` (Array) - array of regexes to match against requested URLs
* `:url_whitelist` (Array) - array of regexes to match against requested URLs
* `:url_blocklist` (Array) - array of regexes to match against requested URLs, alias `:url_blacklist`
* `:url_allowlist` (Array) - array of regexes to match against requested URLs, alias `:url_whitelist`
* `:emulate` (Symbol) - device from Chrome DevTools' list to emulate, e.g. `:iphone_16`, `:pixel_9`, `:ipad_mini`
* `:mobile` (Boolean) - emulate a mobile device: viewport meta tag and touch events
* `:scale_factor` (Numeric) - device scale factor to emulate
Expand Down
3 changes: 3 additions & 0 deletions lib/capybara/cuprite/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def initialize(app, options = {})
@screen_size ||= DEFAULT_MAXIMIZE_SCREEN_SIZE
@options[:save_path] ||= File.expand_path(Capybara.save_path) if Capybara.save_path

@options[:url_blacklist] = @options.delete(:url_blocklist) if @options.key?(:url_blocklist)
@options[:url_whitelist] = @options.delete(:url_allowlist) if @options.key?(:url_allowlist)

# It's set for debug() to make devtools tab open correctly.
@options[:browser_options] ||= {}
unless @options[:browser_options][:"remote-allow-origins"]
Expand Down
51 changes: 51 additions & 0 deletions spec/browser/extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@
expect(session.html).not_to include("We shouldn't see this.")
end
end

it "keeps blocking urls from the url_blocklist driver option after reset!" do
Capybara.register_driver :cuprite_blocklist do |app|
Capybara::Cuprite::Driver.new(app, @driver.options.merge(url_blocklist: /unwanted/))
end

session = Capybara::Session.new(:cuprite_blocklist, @session.app)

session.visit "/cuprite/url_blacklist"
expect(session).to have_content("We are loading some unwanted action here")
session.within_frame "framename" do
expect(session.html).not_to include("We shouldn't see this.")
end

session.reset!

session.visit "/cuprite/url_blacklist"
expect(session).to have_content("We are loading some unwanted action here")
session.within_frame "framename" do
expect(session.html).not_to include("We shouldn't see this.")
end
end
end

describe "#url_whitelist=" do
Expand Down Expand Up @@ -142,6 +164,35 @@
expect(session).not_to have_content("We shouldn't see this.")
end
end

it "keeps allowing urls from the url_allowlist driver option after reset!" do
Capybara.register_driver :cuprite_allowlist do |app|
Capybara::Cuprite::Driver.new(app,
@driver.options.merge(url_allowlist: [/url_whitelist/, %r{/cuprite/wanted}]))
end

session = Capybara::Session.new(:cuprite_allowlist, @session.app)

session.visit "/cuprite/url_whitelist"
expect(session).to have_content("We are loading some wanted action here")
session.within_frame "framename" do
expect(session).to have_content("We should see this.")
end
session.within_frame "unwantedframe" do
expect(session).not_to have_content("We shouldn't see this.")
end

session.reset!

session.visit "/cuprite/url_whitelist"
expect(session).to have_content("We are loading some wanted action here")
session.within_frame "framename" do
expect(session).to have_content("We should see this.")
end
session.within_frame "unwantedframe" do
expect(session).not_to have_content("We shouldn't see this.")
end
end
end

describe "#raise_on_unhandled_modal=" do
Expand Down
Loading