Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow registering a reset proc with the selenium driver #2186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
clear_local_storage: nil,
clear_session_storage: nil
}.freeze
SPECIAL_OPTIONS = %i[browser clear_local_storage clear_session_storage timeout].freeze
SPECIAL_OPTIONS = %i[browser clear_local_storage clear_session_storage timeout reset].freeze
attr_reader :app, :options

class << self
Expand Down Expand Up @@ -286,6 +286,7 @@ def native_args(args)
end

def clear_browser_state
options[:reset]&.call(self)
delete_all_cookies
clear_storage
rescue *clear_browser_state_errors # rubocop:disable Lint/HandleExceptions
Expand Down
20 changes: 20 additions & 0 deletions spec/selenium_spec_chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: false, clear_session_storage: false))
end

Capybara.register_driver :selenium_with_reset do |app|
chrome_options = {
browser: :chrome,
options: browser_options,
reset: proc { |driver| driver.execute_script "reset proc" }
}
Capybara::Selenium::Driver.new(app, chrome_options)
end

Capybara.register_driver :selenium_driver_subclass_with_chrome do |app|
subclass = Class.new(Capybara::Selenium::Driver)
subclass.new(app, browser: :chrome, options: browser_options, timeout: 30)
Expand Down Expand Up @@ -78,6 +87,17 @@ module TestSessions
end
end

context 'reset' do
it 'runs a reset proc if passed in' do
session = Capybara::Session.new(:selenium_with_reset, TestApp)
allow(session.driver).to receive(:execute_script)
session.visit('/with_js')
session.reset!

expect(session.driver).to have_received(:execute_script).with('reset proc')
end
end

context 'timeout' do
it 'sets the http client read timeout' do
expect(TestSessions::Chrome.driver.browser.send(:bridge).http.read_timeout).to eq 30
Expand Down