Class: Selenium::WebDriver::BiDi::LogInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/bidi/log_inspector.rb

Constant Summary collapse

EVENTS =
{
  entry_added: 'entryAdded'
}.freeze
LOG_LEVEL =
{
  DEBUG: 'debug',
  ERROR: 'error',
  INFO: 'info',
  WARNING: 'warning'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(driver, browsing_context_ids = nil) ⇒ LogInspector

Returns a new instance of LogInspector.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/selenium/webdriver/bidi/log_inspector.rb', line 43

def initialize(driver, browsing_context_ids = nil)
  WebDriver.logger.deprecate('LogInspector class',
                             'Script class with driver.script',
                             id: :log_inspector)

  unless driver.capabilities.web_socket_url
    raise Error::WebDriverError,
          'WebDriver instance must support BiDi protocol'
  end

  @bidi = driver.bidi
  @bidi.session.subscribe('log.entryAdded', browsing_context_ids)
end

Instance Method Details

#on_console_entry(filter_by = nil, &block) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/selenium/webdriver/bidi/log_inspector.rb', line 57

def on_console_entry(filter_by = nil, &block)
  check_valid_filter(filter_by)

  on_log do |params|
    type = params['type']
    console_log_events(params, filter_by, &block) if type.eql?('console')
  end
end

#on_javascript_exception(&block) ⇒ Object



75
76
77
78
79
80
# File 'lib/selenium/webdriver/bidi/log_inspector.rb', line 75

def on_javascript_exception(&block)
  on_log do |params|
    type = params['type']
    javascript_log_events(params, FilterBy.log_level('error'), &block) if type.eql?('javascript')
  end
end

#on_javascript_log(filter_by = nil, &block) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/selenium/webdriver/bidi/log_inspector.rb', line 66

def on_javascript_log(filter_by = nil, &block)
  check_valid_filter(filter_by)

  on_log do |params|
    type = params['type']
    javascript_log_events(params, filter_by, &block) if type.eql?('javascript')
  end
end

#on_log(filter_by = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/selenium/webdriver/bidi/log_inspector.rb', line 82

def on_log(filter_by = nil, &)
  unless filter_by.nil?
    check_valid_filter(filter_by)

    on(:entry_added) do |params|
      yield(params) if params['level'] == filter_by.level
    end
    return
  end

  on(:entry_added, &)
end