Module: Appium::Core::Base::TakesScreenshot
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
| 84 85 86 87 88 89 90 91 92 93 | # File 'lib/appium_lib_core/common/base/screenshot.rb', line 84 def element_screenshot_as(element, format) case format when :base64 bridge.element_screenshot element.id when :png bridge.element_screenshot(element.id).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.
| 63 64 65 66 67 68 69 70 | # File 'lib/appium_lib_core/common/base/screenshot.rb', line 63 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
| 24 25 26 27 28 29 30 31 | # File 'lib/appium_lib_core/common/base/screenshot.rb', line 24 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.
| 103 104 105 106 107 108 109 110 111 | # File 'lib/appium_lib_core/common/base/screenshot.rb', line 103 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
| 44 45 46 47 48 49 50 51 52 53 | # File 'lib/appium_lib_core/common/base/screenshot.rb', line 44 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 |