Class: OperaWatir::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/operawatir/screenshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Screenshot

Returns a new instance of Screenshot.



5
6
7
8
# File 'lib/operawatir/screenshot.rb', line 5

def initialize(parent)
  self.browser = parent.browser
  self.reply   = driver.saveScreenshot(2, [].to_java(:string))
end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



3
4
5
# File 'lib/operawatir/screenshot.rb', line 3

def browser
  @browser
end

#replyObject

Returns the value of attribute reply.



3
4
5
# File 'lib/operawatir/screenshot.rb', line 3

def reply
  @reply
end

Instance Method Details

#blank?Boolean

Is the screenshot blank?

Returns:

  • (Boolean)

    True/false depending on the screenshot is blank.



22
23
24
# File 'lib/operawatir/screenshot.rb', line 22

def blank?
  reply.isBlank
end

#md5String

Lets you get a MD5 sum of the screen.

Returns:



36
37
38
# File 'lib/operawatir/screenshot.rb', line 36

def md5
  reply.getMd5
end

#pngString

Returns the raw byte string of the screenshot in PNG format.

Returns:

  • (String)

    A png image in a raw byte string.



29
30
31
# File 'lib/operawatir/screenshot.rb', line 29

def png
  String.from_java_bytes reply.getPng
end

#save(filename) ⇒ String

Saves screenshot to specified location.

Parameters:

  • Path (String)

    to where you want the screenshot saved.

Returns:

  • (String)

    The full path to the file that was saved.



14
15
16
17
# File 'lib/operawatir/screenshot.rb', line 14

def save(filename)
  File.open(filename, 'w') { |f| f.write png }
  File.expand_path filename
end