123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/bidi/log_inspector.rb

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(driver, browsing_context_ids = nil) ⇒ LogInspector

[ GitHub ]

  
# File 'rb/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

#check_valid_filter(filter_by) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/log_inspector.rb', line 102

def check_valid_filter(filter_by)
  return if filter_by.nil? || filter_by.instance_of?(FilterBy)

  raise "Pass valid FilterBy object. Received: #{filter_by.inspect}"
end

#console_log_events(params, filter_by) {|event| ... } (private)

Yields:

  • (event)
[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/log_inspector.rb', line 108

def console_log_events(params, filter_by)
  event = ConsoleLogEntry.new(
    level: params['level'],
    text: params['text'],
    timestamp: params['timestamp'],
    type: params['type'],
    method: params['method'],
    realm: params['realm'],
    args: params['args'],
    stack_trace: params['stackTrace']
  )

  unless filter_by.nil?
    yield(event) if params['level'] == filter_by.level
    return
  end

  yield(event)
end

#javascript_log_events(params, filter_by) {|event| ... } (private)

Yields:

  • (event)
[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/log_inspector.rb', line 128

def javascript_log_events(params, filter_by)
  event = JavascriptLogEntry.new(
    level: params['level'],
    text: params['text'],
    timestamp: params['timestamp'],
    type: params['type'],
    stack_trace: params['stackTrace']
  )

  unless filter_by.nil?
    yield(event) if params['level'] == filter_by.level
    return
  end

  yield(event)
end

#on(event) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/log_inspector.rb', line 97

def on(event, &)
  event = EVENTS[event] if event.is_a?(Symbol)
  @bidi.add_callback("log.#{event}", &)
end

#on_console_entry(filter_by = nil, &block)

[ GitHub ]

  
# File 'rb/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)

[ GitHub ]

  
# File 'rb/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)

[ GitHub ]

  
# File 'rb/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)

[ GitHub ]

  
# File 'rb/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