class Selenium::WebDriver::Logs

Additional useful methods to extend the Selenium::WebDriver::Logs class with

Public Instance Methods

get(type) click to toggle source

@return [Hash]

Identical to the regular log fetch from Selenium, but stores the logs inside a Hash to be writable later

# File lib/automation_helpers/extensions/selenium/webdriver/logs.rb, line 12
def get(type)
  cached_logs[type] = @bridge.log(type)
end
write_log_to_file(type, file = default_file_path) click to toggle source

@return [Integer]

Write the logs to a filepath (If provided), or default file path (Configured). Returns the filesize as per the regular Ruby Filesystem method

# File lib/automation_helpers/extensions/selenium/webdriver/logs.rb, line 20
def write_log_to_file(type, file = default_file_path)
  get(type) unless cached_logs.key?(type)

  cached_logs[type].each do |log_entry|
    if file == $stdout
      file << log_entry
    else
      File.write(file, log_entry)
    end
  end
end

Private Instance Methods

cached_logs() click to toggle source
# File lib/automation_helpers/extensions/selenium/webdriver/logs.rb, line 38
def cached_logs
  @cached_logs ||= {}
end
default_file_path() click to toggle source
# File lib/automation_helpers/extensions/selenium/webdriver/logs.rb, line 34
def default_file_path
  AutomationHelpers.chrome_log_path || raise(missing_file_path_error)
end
missing_file_path_error() click to toggle source
# File lib/automation_helpers/extensions/selenium/webdriver/logs.rb, line 42
def missing_file_path_error
  'Set the path to store logs using AutomationHelpers.chrome_log_path= or pass in a filepath directly to #write_log_to_file'
end