some cleanups, make it better

This commit is contained in:
John Bintz 2012-09-10 11:44:00 -04:00
parent 608f033c5e
commit 8a526f8c77
7 changed files with 45 additions and 32 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ tmp
index.html index.html
screenshots/ screenshots/
.DS_Store .DS_Store
chromedriver.log

View File

@ -3,7 +3,7 @@
require 'thor' require 'thor'
require 'builder' require 'builder'
$: << File.expand_path('../../lib') $: << File.expand_path('../../lib', __FILE__)
require 'hollandaise' require 'hollandaise'
require 'hollandaise/cli' require 'hollandaise/cli'

View File

@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'sauce' gem.add_dependency 'sauce'
gem.add_dependency 'capybara' gem.add_dependency 'capybara'
gem.add_dependency 'thor' gem.add_dependency 'thor'
gem.add_dependency 'builder' gem.add_dependency 'arbre'
end end

View File

@ -1,6 +1,8 @@
module Hollandaise module Hollandaise
module Browser module Browser
class Base class Base
attr_reader :browser
def run(url) def run(url)
@url = url @url = url
@ -9,8 +11,11 @@ module Hollandaise
selenium.execute_script %{window.resizeTo(1280, 1024)} selenium.execute_script %{window.resizeTo(1280, 1024)}
end end
def take_screenshot(target_dir) def dir
target = target_for(target_dir) @options[:dir]
end
def take_screenshot
target.parent.mkpath target.parent.mkpath
selenium.save_screenshot(target.to_s) selenium.save_screenshot(target.to_s)

View File

@ -12,7 +12,7 @@ module Hollandaise
@selenium ||= ::Sauce::Selenium2.new(info) @selenium ||= ::Sauce::Selenium2.new(info)
end end
def target_for(dir) def target
dir.join(@os.to_s).join("#{@browser} #{@version}.png") dir.join(@os.to_s).join("#{@browser} #{@version}.png")
end end

View File

@ -11,7 +11,7 @@ module Hollandaise
@selenium ||= ::Selenium::WebDriver.for(@browser) @selenium ||= ::Selenium::WebDriver.for(@browser)
end end
def target_for(dir) def target
dir.join("#{@browser}.png") dir.join("#{@browser}.png")
end end
end end

View File

@ -1,3 +1,6 @@
require 'arbre'
require 'pathname'
module Hollandaise module Hollandaise
class CLI < Thor class CLI < Thor
desc "sauce URL BROWSER BROWSER...", "Take screenshots of a URL on Sauce Labs" desc "sauce URL BROWSER BROWSER...", "Take screenshots of a URL on Sauce Labs"
@ -13,43 +16,46 @@ module Hollandaise
browsers = Hollandaise.browsers browsers = Hollandaise.browsers
end end
Hollandaise::Browsers.each(browsers, options) do |browser| browser_objects = Hollandaise::Browsers.for(browsers, options.merge(:dir => dir))
browser_objects.each do |browser|
begin begin
browser.run(url) browser.run(url)
browser.take_screenshot(dir) browser.take_screenshot
ensure ensure
browser.close browser.close
end end
end end
if false html = Arbre::Context.new do
html do
head do
title "Sauce Labs screenshots for #{url}"
end
html = Builder::XmlMarkup.new body do
html.html { table do
html.head { thead do
html.title { "Sauce Labs screenshots for #{url}" } tr do
} browser_objects.each do |browser|
th browser.browser
end
end
end
html.body { tbody do
html.table { browser_objects.each do |browser|
html.tr { td(:valign => :top) do
browsers.each { |browser| html.th(browser) } img(:src => browser.target)
} end
end
html.tr { end
Hollandaise::Browsers.for(browsers).each { |browser| end
html.td(:valign => 'top') { end
html.img(:src => screenshot_target_for(browser)) end
} end
}
}
}
}
}
File.open('index.html', 'wb') { |fh| fh.print html.to_s } File.open('index.html', 'wb') { |fh| fh.print html.to_s }
end
end end
default_task :sauce default_task :sauce