diff --git a/History.md b/History.md index f4476c81..fc9b5d2f 100644 --- a/History.md +++ b/History.md @@ -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 diff --git a/lib/capybara/selenium/driver_specializations/chrome_driver.rb b/lib/capybara/selenium/driver_specializations/chrome_driver.rb index a3472a11..25d8926e 100644 --- a/lib/capybara/selenium/driver_specializations/chrome_driver.rb +++ b/lib/capybara/selenium/driver_specializations/chrome_driver.rb @@ -45,8 +45,8 @@ module Capybara::Selenium::Driver::ChromeDriver 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 diff --git a/lib/capybara/selenium/driver_specializations/edge_driver.rb b/lib/capybara/selenium/driver_specializations/edge_driver.rb index 77655995..82f53560 100644 --- a/lib/capybara/selenium/driver_specializations/edge_driver.rb +++ b/lib/capybara/selenium/driver_specializations/edge_driver.rb @@ -39,8 +39,8 @@ module Capybara::Selenium::Driver::EdgeDriver 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 diff --git a/spec/selenium_spec_chrome.rb b/spec/selenium_spec_chrome.rb index 20ba734f..9ff05905 100644 --- a/spec/selenium_spec_chrome.rb +++ b/spec/selenium_spec_chrome.rb @@ -28,6 +28,22 @@ Capybara.register_driver :selenium_chrome_not_clear_storage do |app| 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) @@ -79,6 +95,26 @@ RSpec.describe 'Capybara::Session with chrome' do 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