appium_lib_core 1.7.2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +11 -0
  4. data/lib/appium_lib_core/android/device/clipboard.rb +4 -4
  5. data/lib/appium_lib_core/android/device/screen.rb +1 -1
  6. data/lib/appium_lib_core/android/uiautomator2/device/battery.rb +2 -2
  7. data/lib/appium_lib_core/common/base.rb +17 -0
  8. data/lib/appium_lib_core/common/base/bridge.rb +1 -0
  9. data/lib/appium_lib_core/common/base/bridge/mjsonwp.rb +15 -0
  10. data/lib/appium_lib_core/common/base/bridge/w3c.rb +19 -0
  11. data/lib/appium_lib_core/common/base/driver.rb +599 -1
  12. data/lib/appium_lib_core/common/base/screenshot.rb +18 -0
  13. data/lib/appium_lib_core/common/device/app_management.rb +87 -0
  14. data/lib/appium_lib_core/common/device/app_state.rb +30 -0
  15. data/lib/appium_lib_core/common/device/battery_status.rb +25 -0
  16. data/lib/appium_lib_core/common/device/clipboard_content_type.rb +11 -0
  17. data/lib/appium_lib_core/common/device/context.rb +38 -0
  18. data/lib/appium_lib_core/common/device/device.rb +19 -0
  19. data/lib/appium_lib_core/common/device/device_lock.rb +22 -0
  20. data/lib/appium_lib_core/common/device/file_management.rb +26 -0
  21. data/lib/appium_lib_core/common/device/image_comparison.rb +168 -0
  22. data/lib/appium_lib_core/common/device/ime_actions.rb +29 -0
  23. data/lib/appium_lib_core/common/device/keyboard.rb +22 -0
  24. data/lib/appium_lib_core/common/device/keyevent.rb +38 -0
  25. data/lib/appium_lib_core/common/device/screen_record.rb +54 -0
  26. data/lib/appium_lib_core/common/device/setting.rb +17 -0
  27. data/lib/appium_lib_core/common/device/touch_actions.rb +21 -0
  28. data/lib/appium_lib_core/common/device/value.rb +19 -0
  29. data/lib/appium_lib_core/device.rb +24 -547
  30. data/lib/appium_lib_core/driver.rb +14 -9
  31. data/lib/appium_lib_core/element/image.rb +1 -1
  32. data/lib/appium_lib_core/ios/device/clipboard.rb +4 -4
  33. data/lib/appium_lib_core/ios/xcuitest/device/battery.rb +2 -2
  34. data/lib/appium_lib_core/ios/xcuitest/device/performance.rb +1 -3
  35. data/lib/appium_lib_core/ios/xcuitest/device/screen.rb +1 -1
  36. data/lib/appium_lib_core/ios_xcuitest.rb +0 -2
  37. data/lib/appium_lib_core/version.rb +2 -2
  38. data/release_notes.md +10 -0
  39. metadata +18 -17
  40. data/lib/appium_lib_core/device/app_management.rb +0 -113
  41. data/lib/appium_lib_core/device/app_state.rb +0 -32
  42. data/lib/appium_lib_core/device/battery_status.rb +0 -23
  43. data/lib/appium_lib_core/device/clipboard_content_type.rb +0 -9
  44. data/lib/appium_lib_core/device/context.rb +0 -48
  45. data/lib/appium_lib_core/device/device_lock.rb +0 -28
  46. data/lib/appium_lib_core/device/file_management.rb +0 -32
  47. data/lib/appium_lib_core/device/image_comparison.rb +0 -178
  48. data/lib/appium_lib_core/device/ime_actions.rb +0 -43
  49. data/lib/appium_lib_core/device/keyboard.rb +0 -26
  50. data/lib/appium_lib_core/device/keyevent.rb +0 -44
  51. data/lib/appium_lib_core/device/screen_record.rb +0 -56
  52. data/lib/appium_lib_core/device/setting.rb +0 -21
  53. data/lib/appium_lib_core/device/touch_actions.rb +0 -22
  54. data/lib/appium_lib_core/device/value.rb +0 -23
@@ -1,28 +0,0 @@
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
@@ -1,32 +0,0 @@
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
@@ -1,178 +0,0 @@
1
- require 'base64'
2
-
3
- module Appium
4
- module Core
5
- module Device
6
- module ImageComparison
7
- MODE = [:matchFeatures, :getSimilarity, :matchTemplate].freeze
8
-
9
- MATCH_FEATURES = {
10
- detector_name: %w(AKAZE AGAST BRISK FAST GFTT KAZE MSER SIFT ORB),
11
- match_func: %w(FlannBased BruteForce BruteForceL1 BruteForceHamming BruteForceHammingLut BruteForceSL2),
12
- goodMatchesFactor: nil, # Integer
13
- visualize: [true, false]
14
- }.freeze
15
-
16
- MATCH_TEMPLATE = {
17
- visualize: [true, false]
18
- }.freeze
19
-
20
- GET_SIMILARITY = {
21
- visualize: [true, false]
22
- }.freeze
23
-
24
- # @!method match_images_features(first_image:, second_image:, detector_name: 'ORB',
25
- # match_func: 'BruteForce', good_matches_factor: 100, visualize: false)
26
- # Performs images matching by features with default options. Read https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html
27
- # for more details on this topic.
28
- #
29
- # @param [String] first_image An image data. All image formats, that OpenCV library itself accepts, are supported.
30
- # @param [String] second_image An image data. All image formats, that OpenCV library itself accepts, are supported.
31
- # @param [String] detector_name Sets the detector name for features matching
32
- # algorithm. Some of these detectors (FAST, AGAST, GFTT, FAST, SIFT and MSER) are
33
- # not available in the default OpenCV installation and have to be enabled manually
34
- # before library compilation. The default detector name is 'ORB'.
35
- # @param [String] match_func The name of the matching function. The default one is 'BruteForce'.
36
- # @param [String] good_matches_factor The maximum count of "good" matches (e. g. with minimal distances).
37
- # The default one is nil.
38
- # @param [Bool] visualise Makes the endpoint to return an image, which contains the visualized result of
39
- # the corresponding picture matching operation. This option is disabled by default.
40
- #
41
- # @example
42
- # @driver.match_images_features first_image: "image data 1", second_image: "image data 2"
43
- #
44
- # visual = @@driver.match_images_features first_image: image1, second_image: image2, visualize: true
45
- # File.write 'match_images_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG
46
- #
47
-
48
- # @!method find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
49
- # Performs images matching by template to find possible occurrence of the partial image
50
- # in the full image with default options. Read https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html
51
- # for more details on this topic.
52
- #
53
- # @param [String] full_image: A full image data.
54
- # @param [String] partial_image: A partial image data. All image formats, that OpenCV library itself accepts,
55
- # are supported.
56
- # @param [Bool] visualise: Makes the endpoint to return an image, which contains the visualized result of
57
- # the corresponding picture matching operation. This option is disabled by default.
58
- # @param [Float] threshold: [0.5] At what normalized threshold to reject
59
- #
60
- # @example
61
- # @driver.find_image_occurrence full_image: "image data 1", partial_image: "image data 2"
62
- #
63
- # visual = @@driver.find_image_occurrence full_image: image1, partial_image: image2, visualize: true
64
- # File.write 'find_result_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG
65
- #
66
-
67
- # @!method get_images_similarity(first_image:, second_image:, detector_name: 'ORB', visualize: false)
68
- # Performs images matching to calculate the similarity score between them
69
- # with default options. The flow there is similar to the one used in `find_image_occurrence`
70
- # but it is mandatory that both images are of equal size.
71
- #
72
- # @param [String] first_image: An image data. All image formats, that OpenCV library itself accepts, are supported.
73
- # @param [String] second_image: An image data. All image formats, that OpenCV library itself accepts, are supported.
74
- # @param [Bool] visualise: Makes the endpoint to return an image, which contains the visualized result of
75
- # the corresponding picture matching operation. This option is disabled by default.
76
- #
77
- # @example
78
- # @driver.get_images_similarity first_image: "image data 1", second_image: "image data 2"
79
- #
80
- # visual = @@driver.get_images_similarity first_image: image1, second_image: image2, visualize: true
81
- # File.write 'images_similarity_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG
82
- #
83
-
84
- # @!method compare_images(mode:, first_image:, second_image:, options:)
85
- #
86
- # Performs images comparison using OpenCV framework features.
87
- # It is expected that both OpenCV framework and opencv4nodejs
88
- # module are installed on the machine where Appium server is running.
89
- #
90
- # @param [Symbol] mode: One of possible comparison modes: `:matchFeatures`, `:getSimilarity`, `:matchTemplate`.
91
- # `:matchFeatures is by default.
92
- # @param [String] first_image: An image data. All image formats, that OpenCV library itself accepts, are supported.
93
- # @param [String] second_image: An image data. All image formats, that OpenCV library itself accepts, are supported.
94
- # @param [Hash] options: The content of this dictionary depends on the actual `mode` value.
95
- # See the documentation on `appium-support` module for more details.
96
- # @returns [Hash] The content of the resulting dictionary depends on the actual `mode` and `options` values.
97
- # See the documentation on `appium-support` module for more details.
98
- #
99
-
100
- ####
101
- ## class << self
102
- ####
103
-
104
- def self.add_methods
105
- ::Appium::Core::Device.add_endpoint_method(:match_images_features) do
106
- def match_images_features(first_image:, # rubocop:disable Metrics/ParameterLists
107
- second_image:,
108
- detector_name: 'ORB',
109
- match_func: 'BruteForce',
110
- good_matches_factor: nil,
111
- visualize: false)
112
- unless ::Appium::Core::Device::ImageComparison::MATCH_FEATURES[:detector_name].member?(detector_name.to_s)
113
- raise "detector_name should be #{::Appium::Core::Device::ImageComparison::MATCH_FEATURES[:detector_name]}"
114
- end
115
- unless ::Appium::Core::Device::ImageComparison::MATCH_FEATURES[:match_func].member?(match_func.to_s)
116
- raise "match_func should be #{::Appium::Core::Device::ImageComparison::MATCH_FEATURES[:match_func]}"
117
- end
118
- unless ::Appium::Core::Device::ImageComparison::MATCH_FEATURES[:visualize].member?(visualize)
119
- raise "visualize should be #{::Appium::Core::Device::ImageComparison::MATCH_FEATURES[:visualize]}"
120
- end
121
-
122
- options = {}
123
- options[:detectorName] = detector_name.to_s.upcase
124
- options[:matchFunc] = match_func.to_s
125
- options[:goodMatchesFactor] = good_matches_factor.to_i unless good_matches_factor.nil?
126
- options[:visualize] = visualize
127
-
128
- compare_images(mode: :matchFeatures, first_image: first_image, second_image: second_image, options: options)
129
- end
130
- end
131
-
132
- ::Appium::Core::Device.add_endpoint_method(:find_image_occurrence) do
133
- def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
134
- unless ::Appium::Core::Device::ImageComparison::MATCH_TEMPLATE[:visualize].member?(visualize)
135
- raise "visualize should be #{::Appium::Core::Device::ImageComparison::MATCH_TEMPLATE[:visualize]}"
136
- end
137
-
138
- options = {}
139
- options[:visualize] = visualize
140
- options[:threshold] = threshold unless threshold.nil?
141
-
142
- compare_images(mode: :matchTemplate, first_image: full_image, second_image: partial_image, options: options)
143
- end
144
- end
145
-
146
- ::Appium::Core::Device.add_endpoint_method(:get_images_similarity) do
147
- def get_images_similarity(first_image:, second_image:, visualize: false)
148
- unless ::Appium::Core::Device::ImageComparison::GET_SIMILARITY[:visualize].member?(visualize)
149
- raise "visualize should be #{::Appium::Core::Device::ImageComparison::GET_SIMILARITY[:visualize]}"
150
- end
151
-
152
- options = {}
153
- options[:visualize] = visualize
154
-
155
- compare_images(mode: :getSimilarity, first_image: first_image, second_image: second_image, options: options)
156
- end
157
- end
158
-
159
- ::Appium::Core::Device.add_endpoint_method(:compare_images) do
160
- def compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil)
161
- unless ::Appium::Core::Device::ImageComparison::MODE.member?(mode)
162
- raise "content_type should be #{::Appium::Core::Device::ImageComparison::MODE}"
163
- end
164
-
165
- params = {}
166
- params[:mode] = mode
167
- params[:firstImage] = Base64.encode64 first_image
168
- params[:secondImage] = Base64.encode64 second_image
169
- params[:options] = options if options
170
-
171
- execute(:compare_images, {}, params)
172
- end
173
- end
174
- end # self
175
- end # module ImageComparison
176
- end # module Device
177
- end # module Core
178
- end # module Appium
@@ -1,43 +0,0 @@
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
@@ -1,26 +0,0 @@
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
@@ -1,44 +0,0 @@
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
@@ -1,56 +0,0 @@
1
- module Appium
2
- module Core
3
- module Device
4
- class ScreenRecord
5
- #
6
- # @api private
7
- #
8
-
9
- attr_reader :upload_option
10
-
11
- METHOD = %w(POST PUT).freeze
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
-
34
- def initialize(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_restart: nil)
35
- @upload_option = if remote_path.nil?
36
- {}
37
- else
38
- raise 'method should be POST or PUT' unless METHOD.member?(method.to_s.upcase)
39
-
40
- option = {}
41
- option[:remotePath] = remote_path
42
- option[:user] = user unless user.nil?
43
- option[:pass] = pass unless pass.nil?
44
- option[:method] = method
45
- option
46
- end
47
-
48
- return if force_restart.nil?
49
-
50
- raise 'force_restart should be true or false' unless [true, false].member?(force_restart)
51
- @upload_option[:forceRestart] = force_restart
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,21 +0,0 @@
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
@@ -1,22 +0,0 @@
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