Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Add support for Browser#screenshot API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmo committed Aug 15, 2012
1 parent 50aeb15 commit c1f091d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Gemfile.lock
Expand Up @@ -7,6 +7,7 @@ PATH
rautomation (~> 0.7.2)
user-choices
win32-process (>= 0.5.5)
win32screenshot
windows-pr (>= 0.6.6)
yajl-ruby

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/watir-classic/ie-class.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/watir-classic/ie.rb
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions lib/watir-classic/screenshot.rb
@@ -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
1 change: 1 addition & 0 deletions watir-classic.gemspec
Expand Up @@ -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")
Expand Down

0 comments on commit c1f091d

Please sign in to comment.