appium_lib_core 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -2
  3. data/CHANGELOG.md +16 -0
  4. data/lib/appium_lib_core/android/device.rb +301 -406
  5. data/lib/appium_lib_core/android/device/clipboard.rb +42 -0
  6. data/lib/appium_lib_core/android/device/emulator.rb +149 -147
  7. data/lib/appium_lib_core/android/device/network.rb +47 -0
  8. data/lib/appium_lib_core/android/device/performance.rb +24 -0
  9. data/lib/appium_lib_core/android/device/screen.rb +39 -0
  10. data/lib/appium_lib_core/android/espresso/bridge.rb +1 -1
  11. data/lib/appium_lib_core/android/uiautomator1/bridge.rb +1 -1
  12. data/lib/appium_lib_core/android/uiautomator2/bridge.rb +1 -1
  13. data/lib/appium_lib_core/android/uiautomator2/device.rb +3 -14
  14. data/lib/appium_lib_core/android/uiautomator2/device/battery.rb +28 -0
  15. data/lib/appium_lib_core/common/base/http_default.rb +5 -1
  16. data/lib/appium_lib_core/device.rb +50 -370
  17. data/lib/appium_lib_core/device/app_management.rb +113 -0
  18. data/lib/appium_lib_core/device/app_state.rb +18 -1
  19. data/lib/appium_lib_core/device/context.rb +48 -0
  20. data/lib/appium_lib_core/device/device_lock.rb +28 -0
  21. data/lib/appium_lib_core/device/file_management.rb +32 -0
  22. data/lib/appium_lib_core/device/image_comparison.rb +1 -3
  23. data/lib/appium_lib_core/device/ime_actions.rb +43 -0
  24. data/lib/appium_lib_core/device/keyboard.rb +26 -0
  25. data/lib/appium_lib_core/device/keyevent.rb +44 -0
  26. data/lib/appium_lib_core/device/screen_record.rb +21 -0
  27. data/lib/appium_lib_core/device/setting.rb +21 -0
  28. data/lib/appium_lib_core/device/touch_actions.rb +22 -0
  29. data/lib/appium_lib_core/device/value.rb +23 -0
  30. data/lib/appium_lib_core/driver.rb +8 -0
  31. data/lib/appium_lib_core/ios/device.rb +70 -101
  32. data/lib/appium_lib_core/ios/device/clipboard.rb +41 -0
  33. data/lib/appium_lib_core/ios/uiautomation/bridge.rb +1 -1
  34. data/lib/appium_lib_core/ios/xcuitest/bridge.rb +2 -2
  35. data/lib/appium_lib_core/ios/xcuitest/device.rb +166 -227
  36. data/lib/appium_lib_core/ios/xcuitest/device/battery.rb +28 -0
  37. data/lib/appium_lib_core/ios/xcuitest/device/performance.rb +40 -0
  38. data/lib/appium_lib_core/ios/xcuitest/device/screen.rb +30 -0
  39. data/lib/appium_lib_core/version.rb +2 -2
  40. data/release_notes.md +12 -0
  41. metadata +21 -2
@@ -0,0 +1,113 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module AppManagement
5
+ def self.add_methods # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
6
+ ::Appium::Core::Device.add_endpoint_method(:launch_app) do
7
+ def launch_app
8
+ execute :launch_app
9
+ end
10
+ end
11
+
12
+ ::Appium::Core::Device.add_endpoint_method(:close_app) do
13
+ def close_app
14
+ execute :close_app
15
+ end
16
+ end
17
+
18
+ ::Appium::Core::Device.add_endpoint_method(:close_app) do
19
+ def close_app
20
+ execute :close_app
21
+ end
22
+ end
23
+
24
+ ::Appium::Core::Device.add_endpoint_method(:reset) do
25
+ def reset
26
+ execute :reset
27
+ end
28
+ end
29
+
30
+ ::Appium::Core::Device.add_endpoint_method(:app_strings) do
31
+ def app_strings(language = nil)
32
+ opts = language ? { language: language } : {}
33
+ execute :app_strings, {}, opts
34
+ end
35
+ end
36
+
37
+ ::Appium::Core::Device.add_endpoint_method(:background_app) do
38
+ def background_app(duration = 0)
39
+ execute :background_app, {}, seconds: duration
40
+ end
41
+ end
42
+
43
+ ::Appium::Core::Device.add_endpoint_method(:install_app) do
44
+ def install_app(path, # rubocop:disable Metrics/ParameterLists
45
+ replace: nil,
46
+ timeout: nil,
47
+ allow_test_packages: nil,
48
+ use_sdcard: nil,
49
+ grant_permissions: nil)
50
+ args = { appPath: path }
51
+
52
+ args[:options] = {} unless options?(replace, timeout, allow_test_packages, use_sdcard, grant_permissions)
53
+
54
+ args[:options][:replace] = replace unless replace.nil?
55
+ args[:options][:timeout] = timeout unless timeout.nil?
56
+ args[:options][:allowTestPackages] = allow_test_packages unless allow_test_packages.nil?
57
+ args[:options][:useSdcard] = use_sdcard unless use_sdcard.nil?
58
+ args[:options][:grantPermissions] = grant_permissions unless grant_permissions.nil?
59
+
60
+ execute :install_app, {}, args
61
+ end
62
+
63
+ private
64
+
65
+ def options?(replace, timeout, allow_test_packages, use_sdcard, grant_permissions)
66
+ replace.nil? || timeout.nil? || allow_test_packages.nil? || use_sdcard.nil? || grant_permissions.nil?
67
+ end
68
+ end
69
+
70
+ ::Appium::Core::Device.add_endpoint_method(:remove_app) do
71
+ def remove_app(id, keep_data: nil, timeout: nil)
72
+ # required: [['appId'], ['bundleId']]
73
+ args = { appId: id }
74
+
75
+ args[:options] = {} unless keep_data.nil? || timeout.nil?
76
+ args[:options][:keepData] = keep_data unless keep_data.nil?
77
+ args[:options][:timeout] = timeout unless timeout.nil?
78
+
79
+ execute :remove_app, {}, args
80
+ end
81
+ end
82
+
83
+ ::Appium::Core::Device.add_endpoint_method(:app_installed?) do
84
+ def app_installed?(app_id)
85
+ # required: [['appId'], ['bundleId']]
86
+ execute :app_installed?, {}, bundleId: app_id
87
+ end
88
+ end
89
+
90
+ ::Appium::Core::Device.add_endpoint_method(:activate_app) do
91
+ def activate_app(app_id)
92
+ # required: [['appId'], ['bundleId']]
93
+ execute :activate_app, {}, bundleId: app_id
94
+ end
95
+ end
96
+
97
+ ::Appium::Core::Device.add_endpoint_method(:terminate_app) do
98
+ def terminate_app(app_id, timeout: nil)
99
+ # required: [['appId'], ['bundleId']]
100
+ #
101
+ args = { appId: app_id }
102
+
103
+ args[:options] = {} unless timeout.nil?
104
+ args[:options][:timeout] = timeout unless timeout.nil?
105
+
106
+ execute :terminate_app, {}, args
107
+ end
108
+ end
109
+ end
110
+ end # module AppManagement
111
+ end # module Device
112
+ end # module Core
113
+ end # module Appium
@@ -1,7 +1,7 @@
1
1
  module Appium
2
2
  module Core
3
3
  module Device
4
- class AppState
4
+ module AppState
5
5
  STATUS = [
6
6
  :not_installed, # 0
7
7
  :not_running, # 1
@@ -9,6 +9,23 @@ module Appium
9
9
  :running_in_background, # 3
10
10
  :running_in_foreground # 4
11
11
  ].freeze
12
+
13
+ def self.add_methods
14
+ ::Appium::Core::Device.add_endpoint_method(:app_state) do
15
+ def app_state(app_id)
16
+ # required: [['appId'], ['bundleId']]
17
+ response = execute :app_state, {}, appId: app_id
18
+
19
+ case response
20
+ when 0, 1, 2, 3, 4
21
+ ::Appium::Core::Device::AppState::STATUS[response]
22
+ else
23
+ ::Appium::Logger.debug("Unexpected status in app_state: #{response}")
24
+ response
25
+ end
26
+ end
27
+ end
28
+ end
12
29
  end
13
30
  end
14
31
  end
@@ -0,0 +1,48 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module Context
5
+ def self.add_methods
6
+ ::Appium::Core::Device.add_endpoint_method(:within_context) do
7
+ def within_context(context)
8
+ existing_context = current_context
9
+ set_context context
10
+ if block_given?
11
+ result = yield
12
+ set_context existing_context
13
+ result
14
+ else
15
+ set_context existing_context
16
+ end
17
+ end
18
+ end
19
+
20
+ ::Appium::Core::Device.add_endpoint_method(:switch_to_default_context) do
21
+ def switch_to_default_context
22
+ set_context nil
23
+ end
24
+ end
25
+
26
+ ::Appium::Core::Device.add_endpoint_method(:current_context) do
27
+ def current_context
28
+ execute :current_context
29
+ end
30
+ end
31
+
32
+ ::Appium::Core::Device.add_endpoint_method(:available_contexts) do
33
+ def available_contexts
34
+ # return empty array instead of nil on failure
35
+ execute(:available_contexts, {}) || []
36
+ end
37
+ end
38
+
39
+ ::Appium::Core::Device.add_endpoint_method(:set_context) do
40
+ def set_context(context = null)
41
+ execute :set_context, {}, name: context
42
+ end
43
+ end
44
+ end
45
+ end # module ImeActions
46
+ end # module Device
47
+ end # module Core
48
+ end # module Appium
@@ -0,0 +1,28 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module DeviceLock
5
+ def self.add_methods
6
+ ::Appium::Core::Device.add_endpoint_method(:lock) do
7
+ def lock(duration = nil)
8
+ opts = duration ? { seconds: duration } : {}
9
+ execute :lock, {}, opts
10
+ end
11
+ end
12
+
13
+ ::Appium::Core::Device.add_endpoint_method(:device_locked?) do
14
+ def device_locked?
15
+ execute :device_locked?
16
+ end
17
+ end
18
+
19
+ ::Appium::Core::Device.add_endpoint_method(:unlock) do
20
+ def unlock
21
+ execute :unlock
22
+ end
23
+ end
24
+ end
25
+ end # module DeviceLock
26
+ end # module Device
27
+ end # module Core
28
+ end # module Appium
@@ -0,0 +1,32 @@
1
+ require 'base64'
2
+
3
+ module Appium
4
+ module Core
5
+ module Device
6
+ module FileManagement
7
+ def self.add_methods
8
+ ::Appium::Core::Device.add_endpoint_method(:push_file) do
9
+ def push_file(path, filedata)
10
+ encoded_data = Base64.encode64 filedata
11
+ execute :push_file, {}, path: path, data: encoded_data
12
+ end
13
+ end
14
+
15
+ ::Appium::Core::Device.add_endpoint_method(:pull_file) do
16
+ def pull_file(path)
17
+ data = execute :pull_file, {}, path: path
18
+ Base64.decode64 data
19
+ end
20
+ end
21
+
22
+ ::Appium::Core::Device.add_endpoint_method(:pull_folder) do
23
+ def pull_folder(path)
24
+ data = execute :pull_folder, {}, path: path
25
+ Base64.decode64 data
26
+ end
27
+ end
28
+ end
29
+ end # module FileManagement
30
+ end # module Device
31
+ end # module Core
32
+ end # module Appium
@@ -4,8 +4,6 @@ module Appium
4
4
  module Core
5
5
  module Device
6
6
  module ImageComparison
7
- extend Forwardable
8
-
9
7
  MODE = [:matchFeatures, :getSimilarity, :matchTemplate].freeze
10
8
 
11
9
  MATCH_FEATURES = {
@@ -102,7 +100,7 @@ module Appium
102
100
  ## class << self
103
101
  ####
104
102
 
105
- def self.extended
103
+ def self.add_methods
106
104
  ::Appium::Core::Device.add_endpoint_method(:match_images_features) do
107
105
  def match_images_features(first_image:, # rubocop:disable Metrics/ParameterLists
108
106
  second_image:,
@@ -0,0 +1,43 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module ImeActions
5
+ def self.add_methods
6
+ ::Appium::Core::Device.add_endpoint_method(:ime_activate) do
7
+ def ime_activate(ime_name)
8
+ # from Selenium::WebDriver::Remote::OSS
9
+ execute :ime_activate_engine, {}, engine: ime_name
10
+ end
11
+ end
12
+
13
+ ::Appium::Core::Device.add_endpoint_method(:ime_available_engines) do
14
+ def ime_available_engines
15
+ execute :ime_get_available_engines
16
+ end
17
+ end
18
+
19
+ ::Appium::Core::Device.add_endpoint_method(:ime_active_engine) do
20
+ # from Selenium::WebDriver::Remote::OSS
21
+ def ime_active_engine
22
+ execute :ime_get_active_engine
23
+ end
24
+ end
25
+
26
+ ::Appium::Core::Device.add_endpoint_method(:ime_activated) do
27
+ # from Selenium::WebDriver::Remote::OSS
28
+ def ime_activated
29
+ execute :ime_is_activated
30
+ end
31
+ end
32
+
33
+ ::Appium::Core::Device.add_endpoint_method(:ime_deactivate) do
34
+ # from Selenium::WebDriver::Remote::OSS
35
+ def ime_deactivate
36
+ execute :ime_deactivate, {}
37
+ end
38
+ end
39
+ end
40
+ end # module ImeActions
41
+ end # module Device
42
+ end # module Core
43
+ end # module Appium
@@ -0,0 +1,26 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module Keyboard
5
+ def self.add_methods
6
+ ::Appium::Core::Device.add_endpoint_method(:hide_keyboard) do
7
+ def hide_keyboard(close_key = nil, strategy = nil)
8
+ option = {}
9
+
10
+ option[:key] = close_key || 'Done' # default to Done key.
11
+ option[:strategy] = strategy || :pressKey # default to pressKey
12
+
13
+ execute :hide_keyboard, {}, option
14
+ end
15
+ end
16
+
17
+ ::Appium::Core::Device.add_endpoint_method(:is_keyboard_shown) do
18
+ def is_keyboard_shown # rubocop:disable Naming/PredicateName for compatibility
19
+ execute :is_keyboard_shown
20
+ end
21
+ end
22
+ end
23
+ end # module Keyboard
24
+ end # module Device
25
+ end # module Core
26
+ end # module Appium
@@ -0,0 +1,44 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module KeyEvent
5
+ def self.add_methods
6
+ # Only for Selendroid
7
+ ::Appium::Core::Device.add_endpoint_method(:keyevent) do
8
+ def keyevent(key, metastate = nil)
9
+ args = { keycode: key }
10
+ args[:metastate] = metastate if metastate
11
+ execute :keyevent, {}, args
12
+ end
13
+ end
14
+
15
+ ::Appium::Core::Device.add_endpoint_method(:press_keycode) do
16
+ def press_keycode(key, metastate: [], flags: [])
17
+ raise ArgumentError, 'flags should be Array' unless flags.is_a? Array
18
+ raise ArgumentError, 'metastates should be Array' unless metastate.is_a? Array
19
+
20
+ args = { keycode: key }
21
+ args[:metastate] = metastate.reduce(0) { |acc, meta| acc | meta } unless metastate.empty?
22
+ args[:flags] = flags.reduce(0) { |acc, flag| acc | flag } unless flags.empty?
23
+
24
+ execute :press_keycode, {}, args
25
+ end
26
+ end
27
+
28
+ ::Appium::Core::Device.add_endpoint_method(:long_press_keycode) do
29
+ def long_press_keycode(key, metastate: [], flags: [])
30
+ raise ArgumentError, 'flags should be Array' unless flags.is_a? Array
31
+ raise ArgumentError, 'metastates should be Array' unless metastate.is_a? Array
32
+
33
+ args = { keycode: key }
34
+ args[:metastate] = metastate.reduce(0) { |acc, meta| acc | meta } unless metastate.empty?
35
+ args[:flags] = flags.reduce(0) { |acc, flag| acc | flag } unless flags.empty?
36
+
37
+ execute :long_press_keycode, {}, args
38
+ end
39
+ end
40
+ end
41
+ end # module KeyEvent
42
+ end # module Device
43
+ end # module Core
44
+ end # module Appium
@@ -10,6 +10,27 @@ module Appium
10
10
 
11
11
  METHOD = %w(POST PUT).freeze
12
12
 
13
+ def self.add_methods
14
+ ::Appium::Core::Device.add_endpoint_method(:stop_recording_screen) do
15
+ def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT')
16
+ option = ::Appium::Core::Device::ScreenRecord.new(
17
+ remote_path: remote_path, user: user, pass: pass, method: method
18
+ ).upload_option
19
+
20
+ params = option.empty? ? {} : { options: option }
21
+
22
+ execute(:stop_recording_screen, {}, params)
23
+ end
24
+ end
25
+
26
+ ::Appium::Core::Device.add_endpoint_method(:stop_and_save_recording_screen) do
27
+ def stop_and_save_recording_screen(file_path)
28
+ base64data = execute(:stop_recording_screen, {}, {})
29
+ File.open(file_path, 'wb') { |f| f << Base64.decode64(base64data) }
30
+ end
31
+ end
32
+ end
33
+
13
34
  def initialize(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_restart: nil)
14
35
  @upload_option = if remote_path.nil?
15
36
  {}
@@ -0,0 +1,21 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module Setting
5
+ def self.add_methods
6
+ ::Appium::Core::Device.add_endpoint_method(:get_settings) do
7
+ def get_settings
8
+ execute :get_settings, {}
9
+ end
10
+ end
11
+
12
+ ::Appium::Core::Device.add_endpoint_method(:update_settings) do
13
+ def update_settings(settings)
14
+ execute :update_settings, {}, settings: settings
15
+ end
16
+ end
17
+ end
18
+ end # module Setting
19
+ end # module Device
20
+ end # module Core
21
+ end # module Appium
@@ -0,0 +1,22 @@
1
+ module Appium
2
+ module Core
3
+ module Device
4
+ module TouchActions
5
+ def self.add_methods
6
+ ::Appium::Core::Device.add_endpoint_method(:touch_actions) do
7
+ def touch_actions(actions)
8
+ actions = { actions: [actions].flatten }
9
+ execute :touch_actions, {}, actions
10
+ end
11
+ end
12
+
13
+ ::Appium::Core::Device.add_endpoint_method(:multi_touch) do
14
+ def multi_touch(actions)
15
+ execute :multi_touch, {}, actions: actions
16
+ end
17
+ end
18
+ end
19
+ end # module TouchActions
20
+ end # module Device
21
+ end # module Core
22
+ end # module Appium