diff --git a/rb/lib/selenium/webdriver/remote/bridge.rb b/rb/lib/selenium/webdriver/remote/bridge.rb index d36b0cf3e66dc..0715f1b8261a1 100644 --- a/rb/lib/selenium/webdriver/remote/bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bridge.rb @@ -385,6 +385,8 @@ def add_cookie(cookie) end def delete_cookie(name) + raise ArgumentError, 'Cookie name cannot be null or empty' if name.nil? || name.strip.empty? + execute :delete_cookie, name: name end diff --git a/rb/spec/integration/selenium/webdriver/manager_spec.rb b/rb/spec/integration/selenium/webdriver/manager_spec.rb index d8d9d791ddc74..b42e9256e6c5f 100644 --- a/rb/spec/integration/selenium/webdriver/manager_spec.rb +++ b/rb/spec/integration/selenium/webdriver/manager_spec.rb @@ -253,6 +253,16 @@ module WebDriver expect { driver.manage.cookie_named('non-existent') } .to raise_exception(Error::NoSuchCookieError) end + + it 'throws an error when cookie name is an empty string' do + expect { driver.manage.delete_cookie('') } + .to raise_error(ArgumentError, /Cookie name cannot be null or empty/) + end + + it 'throws an error when cookie name is nil' do + expect { driver.manage.delete_cookie(nil) } + .to raise_error(ArgumentError, /Cookie name cannot be null or empty/) + end end end # Options end # WebDriver