Module: Appium::Core::Base::TakeScreenshot
- Included in:
- Driver
- Defined in:
- lib/appium_lib_core/common/base/screenshot.rb
Instance Method Summary collapse
-
#element_screenshot_as(element, format) ⇒ Object
Return a PNG screenshot in the given format as a string.
-
#save_element_screenshot(element, png_path) ⇒ File
(also: #take_element_screenshot)
Path to the screenshot.
-
#save_screenshot(png_path) ⇒ Object
Save a PNG screenshot to the given path.
-
#save_viewport_screenshot ⇒ Object
Save screenshot except for status bar while ‘@driver.save_screenshot` save entire screen.
-
#screenshot_as(format) ⇒ Object
Return a PNG screenshot in the given format as a string.
Instance Method Details
#element_screenshot_as(element, format) ⇒ Object
Return a PNG screenshot in the given format as a string
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/appium_lib_core/common/base/screenshot.rb', line 70 def element_screenshot_as(element, format) case format when :base64 bridge.take_element_screenshot(element) when :png bridge.take_element_screenshot(element).unpack('m')[0] else raise Core::Error::UnsupportedOperationError, "unsupported format: #{format.inspect}" end end |
#save_element_screenshot(element, png_path) ⇒ File Also known as: take_element_screenshot
Returns Path to the screenshot.
49 50 51 52 53 54 55 56 |
# File 'lib/appium_lib_core/common/base/screenshot.rb', line 49 def save_element_screenshot(element, png_path) extension = File.extname(png_path).downcase if extension != '.png' ::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\ 'It should end with .png extension' end File.open(png_path, 'wb') { |f| f << element_screenshot_as(element, :png) } end |
#save_screenshot(png_path) ⇒ Object
Save a PNG screenshot to the given path
10 11 12 13 14 15 16 17 |
# File 'lib/appium_lib_core/common/base/screenshot.rb', line 10 def save_screenshot(png_path) extension = File.extname(png_path).downcase if extension != '.png' ::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\ 'It should end with .png extension' end File.open(png_path, 'wb') { |f| f << screenshot_as(:png) } end |
#save_viewport_screenshot ⇒ Object
Save screenshot except for status bar while ‘@driver.save_screenshot` save entire screen.
89 90 91 92 93 94 95 96 97 |
# File 'lib/appium_lib_core/common/base/screenshot.rb', line 89 def (png_path) extension = File.extname(png_path).downcase if extension != '.png' ::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\ 'It should end with .png extension' end = bridge. File.open(png_path, 'wb') { |f| f << .unpack('m')[0] } end |
#screenshot_as(format) ⇒ Object
Return a PNG screenshot in the given format as a string
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/appium_lib_core/common/base/screenshot.rb', line 30 def screenshot_as(format) case format when :base64 bridge.screenshot when :png bridge.screenshot.unpack('m')[0] else raise Core::Error::UnsupportedOperationError, "unsupported format: #{format.inspect}" end end |