This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Browser#screenshot API.
- Loading branch information
Showing
5 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters