Module: Selenium::WebDriver::DriverExtensions::HasAuthentication Private

Defined in:
rb/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#register(username:, password:, uri: //) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Registers basic authentication handler which is automatically used whenever browser gets an authentication required response. This currently relies on DevTools so is only supported in Chromium browsers.

Examples:

Authenticate any request

driver.register(username: 'admin', password: '123456')

Authenticate based on URL

driver.register(username: 'admin1', password: '123456', uri: /mysite1\.com/)
driver.register(username: 'admin2', password: '123456', uri: /mysite2\.com/)

Parameters:

  • username (String)
  • password (String)
  • uri (Regexp) (defaults to: //)

    to associate the credentials with



42
43
44
45
46
47
48
49
50
51
52
53
# 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