Sha256: e4ba692e827f371cad4e03282471ad0241c8c88dbb88d5874267eb476a330413

Contents?: true

Size: 623 Bytes

Versions: 4

Compression:

Stored size: 623 Bytes

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-classic-3.3.0 lib/watir-classic/screenshot.rb
watir-classic-3.2.0 lib/watir-classic/screenshot.rb
watir-classic-3.2.0.rc1 lib/watir-classic/screenshot.rb
watir-classic-3.1.0 lib/watir-classic/screenshot.rb