Skip to content

Commit

Permalink
Test single storage type clearing with Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jul 26, 2019
1 parent 6d3fff1 commit 9c61fd4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Release date: unreleased
* Only default puma settings to `queue_requests: false` when using SSL
* Visibility of descendants of <details> elements is correctly determined when using rack_test
and the selenium driver with Capybara optimized atoms
* local/session storage clearance in Chrome when clearing only one of them - Issue #2233

# Version 3.26.0
Release date: 2019-07-15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def reset!

timer = Capybara::Helpers.timer(expire_in: 10)
begin
@browser.navigate.to('about:blank')
clear_storage unless uniform_storage_clear?
@browser.navigate.to('about:blank')
wait_for_empty_page(timer)
rescue *unhandled_alert_errors
accept_unhandled_reset_alert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def reset!

timer = Capybara::Helpers.timer(expire_in: 10)
begin
@browser.navigate.to('about:blank')
clear_storage unless uniform_storage_clear?
@browser.navigate.to('about:blank')
wait_for_empty_page(timer)
rescue *unhandled_alert_errors
accept_unhandled_reset_alert
Expand Down
36 changes: 36 additions & 0 deletions spec/selenium_spec_chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: false, clear_session_storage: false))
end

Capybara.register_driver :selenium_chrome_not_clear_session_storage do |app|
chrome_options = {
browser: :chrome,
options: browser_options
}
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_session_storage: false))
end

Capybara.register_driver :selenium_chrome_not_clear_local_storage do |app|
chrome_options = {
browser: :chrome,
options: browser_options
}
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: false))
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 @@ -79,6 +95,26 @@ module TestSessions
expect(session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
expect(session.evaluate_script('Object.keys(sessionStorage)')).not_to be_empty
end

it 'can not clear session storage' do
session = Capybara::Session.new(:selenium_chrome_not_clear_session_storage, TestApp)
session.visit('/with_js')
session.find(:css, '#set-storage').click
session.reset!
session.visit('/with_js')
expect(session.evaluate_script('Object.keys(localStorage)')).to be_empty
expect(session.evaluate_script('Object.keys(sessionStorage)')).not_to be_empty
end

it 'can not clear local storage' do
session = Capybara::Session.new(:selenium_chrome_not_clear_local_storage, TestApp)
session.visit('/with_js')
session.find(:css, '#set-storage').click
session.reset!
session.visit('/with_js')
expect(session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
expect(session.evaluate_script('Object.keys(sessionStorage)')).to be_empty
end
end
end

Expand Down

0 comments on commit 9c61fd4

Please sign in to comment.