Compare commits

..

No commits in common. "master" and "cleanup" have entirely different histories.

10 changed files with 15 additions and 125 deletions

View File

@ -28,10 +28,7 @@ On Sauce labs:
* `chromewin` * `chromewin`
* `ffwin10` * `ffwin10`
### Projects Make more on the `Hollandaise::Browsers` module! All sorts of flavors!
`hollandaise project NAME` creates a new `hollandaise.rb` file. Fill it in with your project details.
`hollandaise cook` runs that project, making appropriately-named directories. Sweet!
## Adding your own ingredients ## Adding your own ingredients

View File

@ -8,7 +8,10 @@ $: << File.expand_path('../../lib', __FILE__)
require 'hollandaise' require 'hollandaise'
require 'hollandaise/cli' require 'hollandaise/cli'
Hollandaise.load_config! begin
load File.join(Dir.pwd, 'hollandaise.rb')
rescue LoadError => e
end
Hollandaise::CLI.start Hollandaise::CLI.start

View File

@ -19,7 +19,5 @@ Gem::Specification.new do |gem|
gem.add_dependency 'capybara' gem.add_dependency 'capybara'
gem.add_dependency 'thor' gem.add_dependency 'thor'
gem.add_dependency 'arbre' gem.add_dependency 'arbre'
gem.add_dependency 'rainbow'
gem.add_dependency 'rack-proxy'
end end

View File

@ -3,8 +3,6 @@ require 'hollandaise/browsers'
require 'hollandaise/project' require 'hollandaise/project'
require 'hollandaise/browser' require 'hollandaise/browser'
require 'hollandaise/railtie' if defined?(Rails::Railtie)
module Hollandaise module Hollandaise
class << self class << self
attr_accessor :url, :browsers, :delay attr_accessor :url, :browsers, :delay
@ -14,17 +12,6 @@ module Hollandaise
yield self yield self
end end
def self.load_config!
begin
load File.join(Dir.pwd, 'hollandaise.rb')
rescue LoadError => e
begin
load File.join(Dir.pwd, 'config/hollandaise.rb')
rescue LoadError => e
end
end
end
def self.project(name) def self.project(name)
project = Project.new(name) project = Project.new(name)
projects << project projects << project

View File

@ -3,12 +3,12 @@ module Hollandaise
class Base class Base
attr_reader :browser attr_reader :browser
def run_and_take_screenshot(url, screen_size = [ 1280, 1024 ]) def run_and_take_screenshot(url)
@url = url @url = url
selenium.navigate.to url selenium.navigate.to url
sleep @options[:delay].to_i sleep @options[:delay].to_i
selenium.manage.window.resize_to(*screen_size) selenium.execute_script %{window.resizeTo(1280, 1024)}
take_screenshot take_screenshot
end end

View File

@ -12,30 +12,8 @@ module Hollandaise
@selenium ||= ::Sauce::Selenium2.new(info) @selenium ||= ::Sauce::Selenium2.new(info)
end end
def run_and_take_screenshot(url, *args)
self.class.start_tunnel if URI(url).host == 'localhost'
super
end
def self.start_tunnel
return @tunnel if @tunnel
@tunnel = ::Sauce::Connect.new
@tunnel.connect
@tunnel.wait_until_ready
at_exit do
@tunnel.disconnect
end
end
def target def target
dir.join(@os.to_s).join("#{@browser} #{@version || 'latest'}.png") dir.join(@os.to_s).join("#{@browser} #{@version}.png")
end
def name
"#{@browser} #{@version} #{@os}"
end end
def info def info

View File

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

View File

@ -1,7 +1,4 @@
require 'uri' require 'uri'
require 'rainbow'
require 'rack/proxy'
require 'base64'
module Hollandaise module Hollandaise
class Project class Project
@ -10,51 +7,7 @@ module Hollandaise
end end
def root(root) def root(root)
@root = root @root = URI(root)
end
def port
32516
end
def proxy_root(root)
uri = URI(root)
@userinfo = uri.userinfo
@host = uri.host
@port = uri.port
@root = "http://localhost:#{port}#{uri.path}"
end
def with_proxy
if !@host
yield
else
proxy = Class.new(Rack::Proxy) do
def initialize(userinfo, host, port)
@userinfo, @host, @port = userinfo, host, port
end
def rewrite_env(env)
env['HTTP_HOST'] = @host
env['SERVER_PORT'] = @port
env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64(@userinfo)}"
env
end
end
server = Thread.new do
Rack::Handler.default.run(proxy.new(@userinfo, @host, @port), :Port => port) do |server|
Thread.current[:server] = server
end
end
yield
server[:server].stop
end
end end
def screenshot(name, uri) def screenshot(name, uri)
@ -67,21 +20,11 @@ module Hollandaise
@browsers = browsers @browsers = browsers
end end
def screen_size(size)
@screen_size = size.split('x').collect(&:to_i)
end
def run def run
puts "Running #{@project_name}".foreground(:green) urls.each do |url, name|
with_proxy do Hollandaise.chdir "#{@project_name}/#{name}" do
urls.each do |url, name| browser_objects.run do |browser|
puts "... #{name} (#{url})".foreground(:yellow) browser.run_and_take_screenshot(url)
Hollandaise.chdir "#{@project_name}/#{name}" do
browser_objects.run do |browser|
puts " ... #{browser.name}".foreground(:white)
browser.run_and_take_screenshot(url, @screen_size)
end
end end
end end
end end
@ -90,7 +33,7 @@ module Hollandaise
private private
def urls def urls
@screenshots.collect do |name, uri| @screenshots.collect do |name, uri|
[ File.join(@root, uri), name ] [ @root.merge(URI(uri)), name ]
end end
end end

View File

@ -1,12 +0,0 @@
module Hollandaise
class Railtie < ::Rails::Railtie
rake_tasks do
desc "Take screenshots from Hollandaise configuration"
task :take_screenshots do
Hollandaise.load_config!
Hollandaise.projects.each(&:run)
end
end
end
end

View File

@ -1,3 +1,3 @@
module Hollandaise module Hollandaise
VERSION = "0.1.1" VERSION = "0.0.1"
end end