Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- # File
- # firesnap.rb
- # Description
- # Take a screen capture of a Firefox browser session in fullscreen (Mac OS X)
- # Dependancies:
- # gem install firewatir rb-appscript trollop
- # Author
- # Michael Andrews <mjands@gmail.com>
- require 'rubygems'
- require 'firewatir'
- module FireWatir
- class Firefox
- require 'appscript'
- include Appscript
- def fullscreen
- f = lambda {
- app('Firefox').activate
- app('System Events').
- application_processes[ 'Firefox.app' ].
- keystroke('f', :using => [ :command_down, :shift_down ])
- }
- f.call # Go into fullscreen
- wait
- sleep(1)
- yield if block_given?
- f.call # Return from fullscreen
- end
- def capture(file, format = 'pdf')
- %x[ screencapture -t #{format} #{file}.#{format} ]
- end
- end
- end
- require 'trollop'
- opts = Trollop::options do
- opt :url, "Input URL", :type => String
- opt :out, "Output file", :type => String
- end
- Trollop::die :url, 'Input URL required' unless opts[:url]
- Trollop::die :out, 'Output file required' unless opts[:out]
- url = opts[:url]
- out = opts[:out].split(/\./)
- browser = Watir::Browser.new
- begin
- browser.goto(url)
- browser.wait
- browser.fullscreen { browser.capture(*out) }
- ensure
- browser.close
- end
Add Comment
Please, Sign In to add comment