Class: Appium::Core::Device::ScreenRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/appium_lib_core/device/screen_record.rb

Constant Summary collapse

METHOD =
%w(POST PUT).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_restart: nil) ⇒ ScreenRecord

Returns a new instance of ScreenRecord.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/appium_lib_core/device/screen_record.rb', line 34

def initialize(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_restart: nil)
  @upload_option = if remote_path.nil?
                     {}
                   else
                     raise 'method should be POST or PUT' unless METHOD.member?(method.to_s.upcase)

                     option = {}
                     option[:remotePath] = remote_path
                     option[:user] = user unless user.nil?
                     option[:pass] = pass unless pass.nil?
                     option[:method] = method
                     option
                   end

  return if force_restart.nil?

  raise 'force_restart should be true or false' unless [true, false].member?(force_restart)
  @upload_option[:forceRestart] = force_restart
end

Instance Attribute Details

#upload_optionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/appium_lib_core/device/screen_record.rb', line 9

def upload_option
  @upload_option
end

Class Method Details

.add_methodsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/appium_lib_core/device/screen_record.rb', line 13

def self.add_methods
  ::Appium::Core::Device.add_endpoint_method(:stop_recording_screen) do
    def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT')
      option = ::Appium::Core::Device::ScreenRecord.new(
        remote_path: remote_path, user: user, pass: pass, method: method
      ).upload_option

      params = option.empty? ? {} : { options: option }

      execute(:stop_recording_screen, {}, params)
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:stop_and_save_recording_screen) do
    def stop_and_save_recording_screen(file_path)
      base64data = execute(:stop_recording_screen, {}, {})
      File.open(file_path, 'wb') { |f| f << Base64.decode64(base64data) }
    end
  end
end