Module: Appium::Core::Device::AppManagement

Defined in:
lib/appium_lib_core/device/app_management.rb

Class Method Summary collapse

Class Method Details

.add_methodsObject

rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/appium_lib_core/device/app_management.rb', line 5

def self.add_methods # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  ::Appium::Core::Device.add_endpoint_method(:launch_app) do
    def launch_app
      execute :launch_app
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:close_app) do
    def close_app
      execute :close_app
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:close_app) do
    def close_app
      execute :close_app
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:reset) do
    def reset
      execute :reset
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:app_strings) do
    def app_strings(language = nil)
      opts = language ? { language: language } : {}
      execute :app_strings, {}, opts
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:background_app) do
    def background_app(duration = 0)
      execute :background_app, {}, seconds: duration
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:install_app) do
    def install_app(path, # rubocop:disable Metrics/ParameterLists
                    replace: nil,
                    timeout: nil,
                    allow_test_packages: nil,
                    use_sdcard: nil,
                    grant_permissions: nil)
      args = { appPath: path }

      args[:options] = {} unless options?(replace, timeout, allow_test_packages, use_sdcard, grant_permissions)

      args[:options][:replace] = replace unless replace.nil?
      args[:options][:timeout] = timeout unless timeout.nil?
      args[:options][:allowTestPackages] = allow_test_packages unless allow_test_packages.nil?
      args[:options][:useSdcard] = use_sdcard unless use_sdcard.nil?
      args[:options][:grantPermissions] = grant_permissions unless grant_permissions.nil?

      execute :install_app, {}, args
    end

    private

    def options?(replace, timeout, allow_test_packages, use_sdcard, grant_permissions)
      replace.nil? || timeout.nil? || allow_test_packages.nil? || use_sdcard.nil? || grant_permissions.nil?
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:remove_app) do
    def remove_app(id, keep_data: nil, timeout: nil)
      # required: [['appId'], ['bundleId']]
      args = { appId: id }

      args[:options] = {} unless keep_data.nil? || timeout.nil?
      args[:options][:keepData] = keep_data unless keep_data.nil?
      args[:options][:timeout] = timeout unless timeout.nil?

      execute :remove_app, {}, args
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:app_installed?) do
    def app_installed?(app_id)
      # required: [['appId'], ['bundleId']]
      execute :app_installed?, {}, bundleId: app_id
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:activate_app) do
    def activate_app(app_id)
      # required: [['appId'], ['bundleId']]
      execute :activate_app, {}, bundleId: app_id
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:terminate_app) do
    def terminate_app(app_id, timeout: nil)
      # required: [['appId'], ['bundleId']]
      #
      args = { appId: app_id }

      args[:options] = {} unless timeout.nil?
      args[:options][:timeout] = timeout unless timeout.nil?

      execute :terminate_app, {}, args
    end
  end
end