Skip to content
Browse files

Fix starting and stopping

  • Loading branch information...
1 parent 9493058 commit 8876ee2599ef5949e6ba62c89fc6187138aa1402 Jeff Rafter committed Aug 22, 2009
Showing with 13 additions and 7 deletions.
  1. +5 −2 bin/crocodile
  2. +1 −1 crocodile.gemspec
  3. +7 −4 lib/crocodile.rb
View
7 bin/crocodile
@@ -9,6 +9,7 @@ if ARGV.size == 0 || ARGV.include?('--help')
puts " --script=SCRIPT Execute arbitrary javascript in the window"
puts " --control=CODE Execute control code"
puts " --timeout=TIMEOUT Stop waiting"
+ puts " --browser=BROWSER Use something like *firefox /usr/bin/firefox-bin"
puts " --help"
exit
end
@@ -27,21 +28,23 @@ height = opt "height"
script = opt "script"
control = opt "control"
timeout = opt "timeout"
+browser = opt "browser"
options = {}
options[:start] = true if ARGV.include? '--start'
-options[:stop] = true if ARGV.include? '--start'
+options[:stop] = true if ARGV.include? '--stop'
options[:width] = width if width
options[:height] = height if height
options[:timeout] = timeout if timeout
+options[:browser] = browser if browser
# Grab the params
params = ARGV.reject{|arg| arg =~ /^--/}
source = params[0] rescue nil
dest = params[1] rescue nil
if source.nil? || dest.nil?
Crocodile.start if options[:start]
- Crocodile.stop if options[:start]
+ Crocodile.stop if options[:stop]
exit
end
View
2 crocodile.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{crocodile}
- s.version = "0.4.1"
+ s.version = "0.4.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jeff Rafter"]
View
11 lib/crocodile.rb
@@ -4,7 +4,7 @@ class Crocodile
HOST = "0.0.0.0"
PORT = 4444
- TIMEOUT = 60
+ TIMEOUT = 10
def self.start
selenium = Selenium::RemoteControl::RemoteControl.new(HOST, PORT, TIMEOUT)
@@ -25,13 +25,16 @@ def self.snap(host, url, dest, options, &block)
:host => HOST || options[:host],
:port => PORT || options[:port],
:timeout_in_second => TIMEOUT || options[:timeout],
- :browser => "*firefox",
+ :browser => options[:browser] || "*firefox",
:url => host)
browser.start_new_browser_session
browser.open url
- browser.get_eval "window.resizeTo(#{options[:width]},#{options[:height]});" if (options[:width] && options[:height])
+ browser.wait_for_page_to_load(TIMEOUT || options[:timeout])
+ if (options[:width] && options[:height])
+ browser.get_eval("window.resizeTo(#{options[:width]},#{options[:height]});")
+ end
yield browser if block
- browser.capture_entire_page_screenshot File.join(File.expand_path('.'), dest), :wait_for => :page
+ browser.capture_entire_page_screenshot File.join(File.expand_path('.'), dest), ''
browser.close_current_browser_session
ensure
stop if options[:stop]

0 comments on commit 8876ee2

Please sign in to comment.
Something went wrong with that request. Please try again.