Module: Appium::Core::Android::Device::Clipboard

Defined in:
lib/appium_lib_core/android/device/clipboard.rb

Class Method Summary collapse

Class Method Details

.add_methodsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/appium_lib_core/android/device/clipboard.rb', line 22

def self.add_methods
  ::Appium::Core::Device.add_endpoint_method(:get_clipboard) do
    def get_clipboard(content_type: :plaintext)
      unless ::Appium::Core::Base::Device::Clipboard::CONTENT_TYPE.member?(content_type)
        raise "content_type should be #{::Appium::Core::Base::Device::Clipboard::CONTENT_TYPE}"
      end

      params = { contentType: content_type }

      data = execute(:get_clipboard, {}, params)
      Base64.decode64 data
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:set_clipboard) do
    def set_clipboard(content:, content_type: :plaintext, label: nil)
      unless ::Appium::Core::Base::Device::Clipboard::CONTENT_TYPE.member?(content_type)
        raise "content_type should be #{::Appium::Core::Base::Device::Clipboard::CONTENT_TYPE}"
      end

      params = {
        contentType: content_type,
        content: Base64.strict_encode64(content)
      }
      params[:label] = label unless label.nil?

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