Module: Selenium::WebDriver::DriverExtensions::HasAuthentication Private
Relationships & Source Files | |
Defined in: | rb/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb |
Instance Method Summary
-
#register(username:, password:, uri: //)
Internal use only
Registers basic authentication handler which is automatically used whenever browser gets an authentication required response.
- #auth_handlers private Internal use only
- #authenticate(request_id, url) private Internal use only
Instance Method Details
#auth_handlers (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb', line 57
def auth_handlers @auth_handlers ||= [] end
#authenticate(request_id, url) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb', line 61
def authenticate(request_id, url) credentials = auth_handlers.find do |handler| url.match?(handler[:uri]) end if credentials devtools.fetch.continue_with_auth( request_id: request_id, auth_challenge_response: { response: 'ProvideCredentials', username: credentials[:username], password: credentials[:password] } ) else devtools.fetch.continue_with_auth( request_id: request_id, auth_challenge_response: { response: 'CancelAuth' } ) end end
#register(username:, password:, uri: //)
Registers basic authentication handler which is automatically used whenever browser gets an authentication required response. This currently relies on ::Selenium::WebDriver::DevTools
so is only supported in ::Selenium::WebDriver::Chromium
browsers.
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb', line 42
def register(username:, password:, uri: //) auth_handlers << {username: username, password: password, uri: uri} devtools.network.set_cache_disabled(cache_disabled: true) devtools.fetch.on(:auth_required) do |params| authenticate(params['requestId'], params.dig('request', 'url')) end devtools.fetch.on(:request_paused) do |params| devtools.fetch.continue_request(request_id: params['requestId']) end devtools.fetch.enable(handle_auth_requests: true) end