Module: WDA::Screenshot

Included in:
WDA
Defined in:
lib/wda_lib/screenshot.rb

Instance Method Summary collapse

Instance Method Details

#screenshot(path) ⇒ Object

Take a screenshot and save to the given path. Format: png.

Example: screenshot ‘/screenshot_folder/screenshot.png’

Parameters:

  • path (String)

    the full path to save the png

Returns:

  • screenshot result [Hash]



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wda_lib/screenshot.rb', line 12

def screenshot(path)
  path.include?('.png')? path : path += '.png'
  p response = get(@base_url + '/screenshot')
  begin
    File.open(path, 'wb') {|f| f.write Base64.decode64(response['value']) }
  rescue IOError => e
    raise "Fail to save to #{path}, error: #{e}"
  end
  p "Screenshot is saved to #{path}"
  return { sessionId: response['sessionId'], status: response['status'] }  
end