Class: Panda::Core::Testing::Support::System::FerrumConsoleLogger
- Inherits:
-
Object
- Object
- Panda::Core::Testing::Support::System::FerrumConsoleLogger
- 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
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ FerrumConsoleLogger
constructor
A new instance of FerrumConsoleLogger.
-
#puts(log_str) ⇒ Object
Ferrum calls this method with CDP protocol events Format: “SEND message_id json” or “RECV message_id json”.
Constructor Details
#initialize ⇒ FerrumConsoleLogger
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
#logs ⇒ Object (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
#clear ⇒ Object
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 |