Class: Panda::Core::Testing::Support::System::FerrumConsoleLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/panda/core/testing/support/system/ferrum_console_logger.rb

Overview

Custom logger for capturing browser console messages via Ferrum/Cuprite Ferrum doesn’t provide a direct API for console messages - instead it uses Chrome DevTools Protocol (CDP) events that are sent to a logger object

Defined Under Namespace

Classes: Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFerrumConsoleLogger

Returns a new instance of FerrumConsoleLogger.



16
17
18
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 16

def initialize
  @logs = []
end

Instance Attribute Details

#logsObject (readonly)

Returns the value of attribute logs.



14
15
16
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 14

def logs
  @logs
end

Instance Method Details

#clearObject



39
40
41
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 39

def clear
  @logs.clear
end

#puts(log_str) ⇒ Object

Ferrum calls this method with CDP protocol events Format: “SEND message_id json” or “RECV message_id json”



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 22

def puts(log_str)
  return unless log_str.is_a?(String)

  parts = log_str.strip.split(" ", 3)
  return if parts.size < 3

  # Parse the JSON data from CDP event
  data = JSON.parse(parts[2])

  # Only capture console-related events
  if console_event?(data)
    @logs << Message.new(log_str)
  end
rescue JSON::ParserError
  # Silently ignore malformed JSON
end