lib/janus/command/validate.rb in janus-cli-0.1.0 vs lib/janus/command/validate.rb in janus-cli-0.2.0
- old
+ new
@@ -1,22 +1,56 @@
+# coding: utf-8
+
+require 'colorize'
+require 'sauce/connect'
+require 'janus/core/engine'
+require 'janus/io/directory'
+require 'janus/io/selenium'
+
module Janus
module Command
class Validate
def initialize(configuration)
@configuration = configuration
end
def execute
+ Sauce::Connect.connect!(quiet: true) if @configuration.tunnel?
+
+ puts 'Validating screenshots...'
+ puts ''
+
+ @configuration.browsers.each do |browser|
+ validate_screenshots_for_browser(browser)
+ end
+ end
+
+ def validate_screenshots_for_browser(browser)
+ puts "#{browser}"
+ puts ''
+
@configuration.tests.each do |test|
- validate_screenshot(test)
+ validate_screenshot(browser, test)
end
+
+ puts ''
end
- def validate_screenshot(test)
- original = Janus::Screenshot.load(test, path: 'output')
- fresh = Janus::Screenshot.capture(test, username: @configuration.username, access_key: @configuration.access_key)
+ def validate_screenshot(browser, test)
+ selenium = Janus::IO::Selenium.new(@configuration.username, @configuration.access_key, browser)
+ fresh = selenium.read(test)
- raise "#{test.name}: Screenshots did not match!" unless original.image == fresh.image
+ directory = Janus::IO::Directory.new(@configuration.directory, browser)
+ original = directory.read(test)
+
+ engine = Janus::Core::Engine.create(@configuration)
+ engine.execute(original, fresh)
+
+ print '✔ '.green
+ rescue
+ print '✖ '.red
+ ensure
+ puts test.name
end
end
end
end