class Zucchini::Log

Constants

YAML_FILE

Attributes

screenshot_log_path[R]

Public Class Methods

exists?(path) click to toggle source
# File lib/zucchini/log.rb, line 54
def self.exists?(path)
  File.exists?(screenshot_log_path(path))
end
new(path) click to toggle source
# File lib/zucchini/log.rb, line 8
def initialize(path)
  @screenshot_log_path = Zucchini::Log.screenshot_log_path(path)
  raise "Screenshot log not found at #{@screenshot_log_path}" unless File.exists?(@screenshot_log_path)
  @screenshots = File.open(@screenshot_log_path, 'r') { |f| YAML.load(f) }
end
parse_automation_log(path, screenshot_log_path = nil) click to toggle source
# File lib/zucchini/log.rb, line 27
def self.parse_automation_log(path, screenshot_log_path = nil)
  automation_log_path = File.join(path, 'Automation Results.plist')

  if File.exists?(automation_log_path)
    log = Plist::parse_xml(automation_log_path)
    raise "Automation log at #{log_path} could not be parsed" unless log
    entries = log["All Samples"]
    screenshots = []

    entries.each do |entry|
      next unless entry['LogType'] == 'Default'
      match = entry["Message"].match(/^Screenshot.*screen '(?<screen>[^']*)'.*orientation '(?<orientation>[^']*)'$/)
      
      if match
        metadata = {:screen => match[:screen], :orientation => match[:orientation] }
        screenshots << metadata
      end
    end

    screenshot_log_path ||= File.join(path, YAML_FILE)
    File.open(screenshot_log_path, 'w') {|f| f.write(screenshots.to_yaml) }
    true
  else
    false
  end
end
screenshot_log_path(path) click to toggle source
# File lib/zucchini/log.rb, line 58
def self.screenshot_log_path(path)
   File.join(path, YAML_FILE)
end

Public Instance Methods

mark_screenshot_as_rotated(sequence_number) click to toggle source
# File lib/zucchini/log.rb, line 19
def mark_screenshot_as_rotated(sequence_number)
  screenshot_metadata(sequence_number)[:rotated] = true
end
save() click to toggle source
# File lib/zucchini/log.rb, line 23
def save
  File.open(@screenshot_log_path, 'w') {|f| f.write(@screenshots.to_yaml) }
end
screenshot_metadata(sequence_number) click to toggle source
# File lib/zucchini/log.rb, line 14
def screenshot_metadata(sequence_number)
  raise "Invalid screenshot sequence number #{sequence_number}" if sequence_number > @screenshots.size
  @screenshots[sequence_number - 1]
end