Class: Watir::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-classic/screenshot.rb

Overview

Returned by Browser#screenshot.

Instance Method Summary collapse

Constructor Details

#initialize(browser_hwnd) ⇒ Screenshot

Returns a new instance of Screenshot.



8
9
10
# File 'lib/watir-classic/screenshot.rb', line 8

def initialize(browser_hwnd)
  @hwnd = browser_hwnd
end

Instance Method Details

#base64String

Returns #png image formatted as base64.

Returns:

  • (String)

    #png image formatted as base64.



29
30
31
# File 'lib/watir-classic/screenshot.rb', line 29

def base64
  Base64.encode64 png
end

#pngString

Returns image in png format.

Returns:

  • (String)

    image in png format.



20
21
22
23
24
25
26
# File 'lib/watir-classic/screenshot.rb', line 20

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

#save(path) ⇒ Object

Save screenshot to the file.

Parameters:

  • path (String)

    path to the image.



15
16
17
# File 'lib/watir-classic/screenshot.rb', line 15

def save(path)
  screenshot.write(path)
end