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
screenshots/
.DS_Store
chromedriver.log

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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