updates for local proxying for auth and stuff
This commit is contained in:
parent
6a2d290bdb
commit
85a1b148db
@ -8,10 +8,7 @@ $: << File.expand_path('../../lib', __FILE__)
|
||||
require 'hollandaise'
|
||||
require 'hollandaise/cli'
|
||||
|
||||
begin
|
||||
load File.join(Dir.pwd, 'hollandaise.rb')
|
||||
rescue LoadError => e
|
||||
end
|
||||
Hollandaise.load_config!
|
||||
|
||||
Hollandaise::CLI.start
|
||||
|
||||
|
@ -19,5 +19,7 @@ Gem::Specification.new do |gem|
|
||||
gem.add_dependency 'capybara'
|
||||
gem.add_dependency 'thor'
|
||||
gem.add_dependency 'arbre'
|
||||
gem.add_dependency 'rainbow'
|
||||
gem.add_dependency 'rack-proxy'
|
||||
end
|
||||
|
||||
|
@ -3,6 +3,8 @@ require 'hollandaise/browsers'
|
||||
require 'hollandaise/project'
|
||||
require 'hollandaise/browser'
|
||||
|
||||
require 'hollandaise/railtie' if defined?(Rails::Railtie)
|
||||
|
||||
module Hollandaise
|
||||
class << self
|
||||
attr_accessor :url, :browsers, :delay
|
||||
@ -12,6 +14,17 @@ module Hollandaise
|
||||
yield self
|
||||
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)
|
||||
project = Project.new(name)
|
||||
projects << project
|
||||
|
@ -3,12 +3,12 @@ module Hollandaise
|
||||
class Base
|
||||
attr_reader :browser
|
||||
|
||||
def run_and_take_screenshot(url)
|
||||
def run_and_take_screenshot(url, screen_size = [ 1280, 1024 ])
|
||||
@url = url
|
||||
|
||||
selenium.navigate.to url
|
||||
sleep @options[:delay].to_i
|
||||
selenium.execute_script %{window.resizeTo(1280, 1024)}
|
||||
selenium.manage.window.resize_to(*screen_size)
|
||||
take_screenshot
|
||||
end
|
||||
|
||||
|
@ -12,8 +12,30 @@ module Hollandaise
|
||||
@selenium ||= ::Sauce::Selenium2.new(info)
|
||||
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
|
||||
dir.join(@os.to_s).join("#{@browser} #{@version}.png")
|
||||
dir.join(@os.to_s).join("#{@browser} #{@version || 'latest'}.png")
|
||||
end
|
||||
|
||||
def name
|
||||
"#{@browser} #{@version} #{@os}"
|
||||
end
|
||||
|
||||
def info
|
||||
|
@ -11,6 +11,10 @@ module Hollandaise
|
||||
@selenium ||= ::Selenium::WebDriver.for(@browser)
|
||||
end
|
||||
|
||||
def name
|
||||
@browser
|
||||
end
|
||||
|
||||
def target
|
||||
dir.join("#{@browser}.png")
|
||||
end
|
||||
|
@ -1,4 +1,7 @@
|
||||
require 'uri'
|
||||
require 'rainbow'
|
||||
require 'rack/proxy'
|
||||
require 'base64'
|
||||
|
||||
module Hollandaise
|
||||
class Project
|
||||
@ -7,7 +10,51 @@ module Hollandaise
|
||||
end
|
||||
|
||||
def root(root)
|
||||
@root = URI(root)
|
||||
@root = 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
|
||||
|
||||
def screenshot(name, uri)
|
||||
@ -20,11 +67,21 @@ module Hollandaise
|
||||
@browsers = browsers
|
||||
end
|
||||
|
||||
def screen_size(size)
|
||||
@screen_size = size.split('x').collect(&:to_i)
|
||||
end
|
||||
|
||||
def run
|
||||
urls.each do |url, name|
|
||||
Hollandaise.chdir "#{@project_name}/#{name}" do
|
||||
browser_objects.run do |browser|
|
||||
browser.run_and_take_screenshot(url)
|
||||
puts "Running #{@project_name}".foreground(:green)
|
||||
with_proxy do
|
||||
urls.each do |url, name|
|
||||
puts "... #{name} (#{url})".foreground(:yellow)
|
||||
|
||||
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
|
||||
@ -33,7 +90,7 @@ module Hollandaise
|
||||
private
|
||||
def urls
|
||||
@screenshots.collect do |name, uri|
|
||||
[ @root.merge(URI(uri)), name ]
|
||||
[ File.join(@root, uri), name ]
|
||||
end
|
||||
end
|
||||
|
||||
|
12
lib/hollandaise/railtie.rb
Normal file
12
lib/hollandaise/railtie.rb
Normal file
@ -0,0 +1,12 @@
|
||||
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
|
@ -1,3 +1,3 @@
|
||||
module Hollandaise
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.1.1"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user