Permalink
Browse files

Add support for Browser#screenshot API.

  • Loading branch information...
1 parent 50aeb15 commit c1f091de91f9388d91931e4567e89cd2a18aa076 @jarmo jarmo committed Aug 15, 2012
Showing with 60 additions and 13 deletions.
  1. +21 −13 Gemfile.lock
  2. +4 −0 lib/watir-classic/ie-class.rb
  3. +1 −0 lib/watir-classic/ie.rb
  4. +33 −0 lib/watir-classic/screenshot.rb
  5. +1 −0 watir-classic.gemspec
View
@@ -7,6 +7,7 @@ PATH
rautomation (~> 0.7.2)
user-choices
win32-process (>= 0.5.5)
+ win32screenshot
windows-pr (>= 0.6.6)
yajl-ruby
@@ -15,39 +16,46 @@ GEM
specs:
builder (3.0.0)
diff-lcs (1.1.3)
- ffi (1.0.11)
- hoe (3.0.3)
+ ffi (1.1.3-x86-mingw32)
+ hoe (3.0.6)
rake (~> 0.8)
- nokogiri (1.5.2-x86-mingw32)
+ mini_magick (3.2.1)
+ subexec (~> 0.0.4)
+ nokogiri (1.5.5-x86-mingw32)
rack (1.4.1)
rack-protection (1.2.0)
rack
rake (0.9.2.2)
rautomation (0.7.2)
- rspec (2.9.0)
- rspec-core (~> 2.9.0)
- rspec-expectations (~> 2.9.0)
- rspec-mocks (~> 2.9.0)
- rspec-core (2.9.0)
- rspec-expectations (2.9.0)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.2)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.9.0)
+ rspec-mocks (2.11.1)
s4t-utils (1.0.4)
hoe (>= 1.3.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ subexec (0.0.4)
syntax (1.0.0)
tilt (1.3.3)
user-choices (1.1.6.1)
builder (>= 2.1.2)
s4t-utils (>= 1.0.3)
xml-simple (>= 1.0.11)
win32-api (1.4.8-x86-mingw32)
- win32-process (0.6.5)
- windows-pr (>= 1.1.2)
- windows-api (0.4.1)
+ win32-process (0.6.6)
+ windows-pr (>= 1.2.2)
+ win32screenshot (1.0.7)
+ ffi (~> 1.0)
+ mini_magick (~> 3.2.1)
+ rautomation (~> 0.7.0)
+ windows-api (0.4.2)
win32-api (>= 1.4.5)
windows-pr (1.2.2)
win32-api (>= 1.4.5)
@@ -497,6 +497,10 @@ def url
return @ie.LocationURL
end
+ def screenshot
+ Screenshot.new(hwnd)
+ end
+
def window(specifiers={}, &blk)
win = Window.new(self, specifiers, &blk)
win.use &blk if blk
View
@@ -2,6 +2,7 @@
require 'watir-classic/core'
require 'watir-classic/close_all'
require 'watir-classic/ie-process'
+require 'watir-classic/screenshot'
# these switches need to be deleted from ARGV to enable the Test::Unit
# functionality that grabs
@@ -0,0 +1,33 @@
+require "tmpdir"
+require "base64"
+require "win32/screenshot"
+
+module Watir
+ class Screenshot
+ def initialize(browser_hwnd)
+ @hwnd = browser_hwnd
+ end
+
+ def save(path)
+ screenshot.write(path)
+ end
+
+ def png
+ path = File.expand_path "temporary-image-#{Time.now.to_i}.png", Dir.tmpdir
+ save path
+ File.open(path, "rb") {|file| file.read}
+ ensure
+ File.delete path rescue nil
+ end
+
+ def base64
+ Base64.encode64 png
+ end
+
+ private
+
+ def screenshot
+ ::Win32::Screenshot::Take.of(:window, :hwnd => @hwnd)
+ end
+ end
+end
View
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
s.add_dependency 'rautomation', '~>0.7.2'
s.add_dependency 'user-choices'
s.add_dependency 'yajl-ruby'
+ s.add_dependency 'win32screenshot'
s.add_development_dependency("rspec", "~>2.3")
s.add_development_dependency("syntax")

0 comments on commit c1f091d

Please sign in to comment.