Skip to content

Commit

Permalink
[rb] Deprecate WebStorage JS methods (SeleniumHQ#14276)
Browse files Browse the repository at this point in the history
Co-authored-by: aguspe <[email protected]>
  • Loading branch information
aguspe and aguspe authored Jul 19, 2024
1 parent 50e3563 commit 0652bfc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def element_screenshot(element)
#

def local_storage_item(key, value = nil)
WebDriver.logger.deprecate('local_storage_item(key, value)', id: :local_storage_item)
if value
execute_script("localStorage.setItem('#{key}', '#{value}')")
else
Expand All @@ -309,22 +310,27 @@ def local_storage_item(key, value = nil)
end

def remove_local_storage_item(key)
WebDriver.logger.deprecate('remove_local_storage_item(key)', id: :remove_local_storage_item)
execute_script("localStorage.removeItem('#{key}')")
end

def local_storage_keys
WebDriver.logger.deprecate('local_storage_keys', id: :local_storage_keys)
execute_script('return Object.keys(localStorage)')
end

def clear_local_storage
WebDriver.logger.deprecate('clear_local_storage', id: :clear_local_storage)
execute_script('localStorage.clear()')
end

def local_storage_size
WebDriver.logger.deprecate('local_storage_size', id: :local_storage_size)
execute_script('return localStorage.length')
end

def session_storage_item(key, value = nil)
WebDriver.logger.deprecate('session_storage_item(key, value)', id: :session_storage_item)
if value
execute_script("sessionStorage.setItem('#{key}', '#{value}')")
else
Expand All @@ -333,18 +339,22 @@ def session_storage_item(key, value = nil)
end

def remove_session_storage_item(key)
WebDriver.logger.deprecate('remove_session_storage_item(key)', id: :remove_session_storage_item)
execute_script("sessionStorage.removeItem('#{key}')")
end

def session_storage_keys
WebDriver.logger.deprecate('session_storage_keys', id: :session_storage_keys)
execute_script('return Object.keys(sessionStorage)')
end

def clear_session_storage
WebDriver.logger.deprecate('clear_session_storage', id: :clear_session_storage)
execute_script('sessionStorage.clear()')
end

def session_storage_size
WebDriver.logger.deprecate('session_storage_size', id: :session_storage_size)
execute_script('return sessionStorage.length')
end

Expand Down
11 changes: 11 additions & 0 deletions rb/spec/integration/selenium/webdriver/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ module DriverExtensions
storage.fetch('no-such-key')
}.to raise_error(IndexError, /missing key/)
end

it 'logs a deprecated warning when calling a deprecated method' do
storage_type = storage.is_a?(HTML5::LocalStorage) ? 'local' : 'session'

expect { storage['foo'] }.to have_deprecated(:"#{storage_type}_storage_item")
expect { storage['foo'] = 'bar' }.to have_deprecated(:"#{storage_type}_storage_item")
expect { storage.delete('foo') }.to have_deprecated(:"remove_#{storage_type}_storage_item")
expect { storage.size }.to have_deprecated(:"#{storage_type}_storage_size")
expect { storage.clear }.to have_deprecated(:"clear_#{storage_type}_storage")
expect { storage.keys }.to have_deprecated(:"#{storage_type}_storage_keys")
end
end

describe 'local storage' do
Expand Down

0 comments on commit 0652bfc

Please sign in to comment.