Guest User

Untitled

a guest
Jun 21st, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. # File
  4. # firesnap.rb
  5. # Description
  6. # Take a screen capture of a Firefox browser session in fullscreen (Mac OS X)
  7. # Dependancies:
  8. # gem install firewatir rb-appscript trollop
  9. # Author
  10. # Michael Andrews <mjands@gmail.com>
  11.  
  12. require 'rubygems'
  13. require 'firewatir'
  14.  
  15. module FireWatir
  16. class Firefox
  17. require 'appscript'
  18. include Appscript
  19.  
  20. def fullscreen
  21. f = lambda {
  22. app('Firefox').activate
  23. app('System Events').
  24. application_processes[ 'Firefox.app' ].
  25. keystroke('f', :using => [ :command_down, :shift_down ])
  26. }
  27.  
  28. f.call # Go into fullscreen
  29. wait
  30. sleep(1)
  31.  
  32. yield if block_given?
  33.  
  34. f.call # Return from fullscreen
  35. end
  36.  
  37. def capture(file, format = 'pdf')
  38. %x[ screencapture -t #{format} #{file}.#{format} ]
  39. end
  40. end
  41. end
  42.  
  43. require 'trollop'
  44.  
  45. opts = Trollop::options do
  46. opt :url, "Input URL", :type => String
  47. opt :out, "Output file", :type => String
  48. end
  49.  
  50. Trollop::die :url, 'Input URL required' unless opts[:url]
  51. Trollop::die :out, 'Output file required' unless opts[:out]
  52.  
  53. url = opts[:url]
  54. out = opts[:out].split(/\./)
  55.  
  56. browser = Watir::Browser.new
  57.  
  58. begin
  59. browser.goto(url)
  60. browser.wait
  61. browser.fullscreen { browser.capture(*out) }
  62. ensure
  63. browser.close
  64. end
Add Comment
Please, Sign In to add comment