Class: Watir::Screenshot

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

Instance Method Summary collapse

Constructor Details

#initialize(browser) ⇒ Screenshot


3
4
5
6
7
8
9
10
11
12
# File 'lib/watir/screenshot.rb', line 3

def initialize(browser)
  if browser.is_a? Selenium::WebDriver::Driver
    msg = 'Initializing `Watir::Screenshot` with a `Selenium::Driver` instance', 'a `Watir::Browser` instance'
    Watir.logger.deprecate msg, ids: [:screenshot_driver]
    @driver = browser
  else
    @browser = browser
    @driver = browser.wd
  end
end

Instance Method Details

#base64String

Represents screenshot as Base64 encoded string.

Examples:

browser.screenshot.base64
#=> '7HWJ43tZDscPleeUuPW6HhN3x+z7vU/lufmH0qNTtTum94IBWMT46evImci1vnFGT'

51
52
53
# File 'lib/watir/screenshot.rb', line 51

def base64
  @driver.screenshot_as(:base64)
end

#pngString

Represents screenshot as PNG image string.

Examples:

browser.screenshot.png
#=> '\x95\xC7\[email protected]\xC07\x1C(Edb\x15\xB2\vL'

37
38
39
# File 'lib/watir/screenshot.rb', line 37

def png
  @driver.screenshot_as(:png)
end

#save(path) ⇒ Object

Saves screenshot to given path.

Examples:

browser.screenshot.save "screenshot.png"

23
24
25
# File 'lib/watir/screenshot.rb', line 23

def save(path)
  @driver.save_screenshot(path)
end