diff --git a/rb/lib/selenium/webdriver/common/manager.rb b/rb/lib/selenium/webdriver/common/manager.rb index 6ba94fca8d829..d080e0ead6ef7 100644 --- a/rb/lib/selenium/webdriver/common/manager.rb +++ b/rb/lib/selenium/webdriver/common/manager.rb @@ -65,7 +65,7 @@ def add_cookie(opts = {}) # Get the cookie with the given name # # @param [String] name the name of the cookie - # @return [Hash, nil] the cookie, or nil if it wasn't found. + # @return [Hash, nil] the cookie, or throws a NoSuchCookieError if it wasn't found. # def cookie_named(name) diff --git a/rb/sig/lib/selenium/webdriver/common/manager.rbs b/rb/sig/lib/selenium/webdriver/common/manager.rbs index bf61f3e18c4b4..bb214a709a84b 100644 --- a/rb/sig/lib/selenium/webdriver/common/manager.rbs +++ b/rb/sig/lib/selenium/webdriver/common/manager.rbs @@ -11,7 +11,7 @@ module Selenium def add_cookie: (?Hash[Symbol, untyped] opts) -> void - def cookie_named: (String name) -> Hash[Symbol, untyped] + def cookie_named: (String name) -> (Hash[Symbol, untyped] | Error::NoSuchCookieError) def delete_cookie: (String name) -> String @@ -33,7 +33,7 @@ module Selenium def strip_port: (String str) -> String? - def convert_cookie: (Hash[String, untyped] cookie) -> Hash[Symbol, untyped] + def convert_cookie: (String) -> (Hash[Symbol, untyped] | Error::NoSuchCookieError) end end end diff --git a/rb/spec/integration/selenium/webdriver/manager_spec.rb b/rb/spec/integration/selenium/webdriver/manager_spec.rb index f06afd7302cc9..d8d9d791ddc74 100644 --- a/rb/spec/integration/selenium/webdriver/manager_spec.rb +++ b/rb/spec/integration/selenium/webdriver/manager_spec.rb @@ -248,6 +248,11 @@ module WebDriver driver.manage.delete_all_cookies expect(driver.manage.all_cookies).to be_empty end + + it 'throws error when fetching non-existent cookie' do + expect { driver.manage.cookie_named('non-existent') } + .to raise_exception(Error::NoSuchCookieError) + end end end # Options end # WebDriver