Module: Selenium::WebDriver::DriverExtensions::HasLogEvents Private

Includes:
Atoms
Defined in:
lib/selenium/webdriver/common/driver_extensions/has_log_events.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.

Constant Summary collapse

KINDS =

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

%i[console exception mutation].freeze

Instance Method Summary collapse

Methods included from Atoms

#atom_script

Instance Method Details

#on_log_event(kind, &block) {|| ... } ⇒ 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 listener to be called whenever browser receives a new Console API message such as console.log() or an unhandled exception.

This currently relies on DevTools so is only supported in Chromium browsers.

Examples:

Collect console messages

logs = []
driver.on_log_event(:console) do |event|
  logs.push(event)
end

Collect JavaScript exceptions

exceptions = []
driver.on_log_event(:exception) do |event|
  exceptions.push(event)
end

Collect DOM mutations

mutations = []
driver.on_log_event(:mutation) do |event|
  mutations.push(event)
end

Parameters:

  • kind (Symbol)

    :console, :exception or :mutation

  • block (#call)

    which is called when event happens

Yield Parameters:

Raises:



59
60
61
62
63
64
65
66
67
68
# File 'lib/selenium/webdriver/common/driver_extensions/has_log_events.rb', line 59

def on_log_event(kind, &block)
  raise Error::WebDriverError, "Don't know how to handle #{kind} events" unless KINDS.include?(kind)

  enabled = log_listeners[kind].any?
  log_listeners[kind] << block
  return if enabled

  devtools.runtime.enable
  __send__(:"log_#{kind}_events")
end