module Selenium::WebDriver::DriverExtensions::TakesScreenshot

Public Instance Methods

save_screenshot(png_path) click to toggle source

Save a PNG screenshot to the given path

@api public

# File lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb, line 17
def save_screenshot(png_path)
  File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
end
screenshot_as(format) click to toggle source

Return a PNG screenshot in the given format as a string

@param [:base64, :png] format @return String screenshot

@api public

# File lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb, line 29
def screenshot_as(format)
  case format
  when :base64
    bridge.getScreenshot
  when :png
    bridge.getScreenshot.unpack("m")[0]
  else
    raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
  end
end