appium_lib_core 4.0.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/unittest.yml +1 -1
  3. data/.rubocop.yml +18 -4
  4. data/CHANGELOG.md +29 -272
  5. data/appium_lib_core.gemspec +1 -1
  6. data/ci-jobs/functional/run_appium.yml +1 -1
  7. data/lib/appium_lib_core.rb +5 -5
  8. data/lib/appium_lib_core/android/device.rb +5 -5
  9. data/lib/appium_lib_core/common/base.rb +1 -0
  10. data/lib/appium_lib_core/common/base/bridge/w3c.rb +1 -0
  11. data/lib/appium_lib_core/common/base/driver.rb +24 -11
  12. data/lib/appium_lib_core/common/base/http_default.rb +2 -3
  13. data/lib/appium_lib_core/common/base/rotable.rb +54 -0
  14. data/lib/appium_lib_core/common/base/screenshot.rb +1 -1
  15. data/lib/appium_lib_core/common/base/search_context.rb +4 -4
  16. data/lib/appium_lib_core/common/command/common.rb +0 -2
  17. data/lib/appium_lib_core/common/command/mjsonwp.rb +0 -2
  18. data/lib/appium_lib_core/common/command/w3c.rb +0 -2
  19. data/lib/appium_lib_core/common/device/app_management.rb +1 -1
  20. data/lib/appium_lib_core/common/device/image_comparison.rb +3 -3
  21. data/lib/appium_lib_core/common/device/orientation.rb +31 -0
  22. data/lib/appium_lib_core/common/wait.rb +2 -2
  23. data/lib/appium_lib_core/driver.rb +5 -3
  24. data/lib/appium_lib_core/ios/xcuitest/device.rb +2 -2
  25. data/lib/appium_lib_core/mac2.rb +17 -0
  26. data/lib/appium_lib_core/mac2/bridge.rb +25 -0
  27. data/lib/appium_lib_core/mac2/device.rb +92 -0
  28. data/lib/appium_lib_core/mac2/device/screen.rb +48 -0
  29. data/lib/appium_lib_core/patch.rb +53 -0
  30. data/lib/appium_lib_core/version.rb +2 -2
  31. data/lib/appium_lib_core/windows/device.rb +2 -2
  32. data/release_notes.md +40 -0
  33. data/script/commands.rb +3 -3
  34. metadata +10 -4
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'minitest', '~> 5.0'
32
32
  spec.add_development_dependency 'minitest-reporters', '~> 1.1'
33
33
  spec.add_development_dependency 'webmock', '~> 3.11.0'
34
- spec.add_development_dependency 'rubocop', '0.68.1'
34
+ spec.add_development_dependency 'rubocop', '1.8.1'
35
35
  spec.add_development_dependency 'appium_thor', '~> 1.0'
36
36
  spec.add_development_dependency 'pry'
37
37
  spec.add_development_dependency 'pry-byebug'
@@ -11,7 +11,7 @@ steps:
11
11
  displayName: Installed node dependencies
12
12
  - task: UseRubyVersion@0
13
13
  inputs:
14
- versionSpec: '2.4' # so far, bundler does not work over 2.5 since it raises openssl error
14
+ versionSpec: '2.7'
15
15
  - script: |
16
16
  mkdir -p test/report
17
17
  nohup appium --relaxed-security --log-timestamp --log-no-colors > test/report/appium.out 2>&1 &
@@ -34,11 +34,11 @@ module Appium
34
34
 
35
35
  hash.each_with_object({}) do |pair, acc|
36
36
  key = begin
37
- pair[0].to_sym
38
- rescue StandardError => e
39
- ::Appium::Logger.warn(e.message)
40
- pair[0]
41
- end
37
+ pair[0].to_sym
38
+ rescue StandardError => e
39
+ ::Appium::Logger.warn(e.message)
40
+ pair[0]
41
+ end
42
42
 
43
43
  value = pair[1]
44
44
  acc[key] = value.is_a?(Hash) ? symbolize_keys(value) : value
@@ -25,7 +25,7 @@ module Appium
25
25
  module Device
26
26
  extend Forwardable
27
27
 
28
- # rubocop:disable Metrics/LineLength
28
+ # rubocop:disable Layout/LineLength
29
29
 
30
30
  # @!method open_notifications
31
31
  # Open Android notifications
@@ -290,16 +290,16 @@ module Appium
290
290
  # @driver.finger_print 1
291
291
  #
292
292
 
293
- # @!method execute_cdp(cmd, params)
293
+ # @!method execute_cdp(cmd, **params)
294
294
  # Execute Chrome Devtools protocol commands
295
295
  # https://chromedevtools.github.io/devtools-protocol
296
296
  #
297
297
  # @param [String] cmd The name of command
298
- # @param [Hash] params The parameter for the command as hash.
298
+ # @option params The parameter for the command as keyword options.
299
299
  #
300
300
  # @example
301
301
  #
302
- # @driver.execute_cdp 'Page.captureScreenshot', { quality: 50, format: 'jpeg' }
302
+ # @driver.execute_cdp 'Page.captureScreenshot', quality: 50, format: 'jpeg'
303
303
  # @driver.execute_cdp 'Page.getResourceTree'
304
304
  #
305
305
 
@@ -307,7 +307,7 @@ module Appium
307
307
  ## class << self
308
308
  ####
309
309
 
310
- # rubocop:enable Metrics/LineLength
310
+ # rubocop:enable Layout/LineLength
311
311
 
312
312
  class << self
313
313
  def extended(_mod)
@@ -29,6 +29,7 @@ require_relative 'device/clipboard_content_type'
29
29
  require_relative 'device/device'
30
30
  require_relative 'device/touch_actions'
31
31
  require_relative 'device/execute_driver'
32
+ require_relative 'device/orientation'
32
33
 
33
34
  # The following files have selenium-webdriver related stuff.
34
35
  require_relative 'base/driver'
@@ -32,6 +32,7 @@ module Appium
32
32
  include Device::Device
33
33
  include Device::TouchActions
34
34
  include Device::ExecuteDriver
35
+ include Device::Orientation
35
36
 
36
37
  def commands(command)
37
38
  ::Appium::Core::Commands::W3C::COMMANDS[command]
@@ -15,6 +15,7 @@
15
15
  require 'base64'
16
16
  require_relative 'search_context'
17
17
  require_relative 'screenshot'
18
+ require_relative 'rotable'
18
19
 
19
20
  module Appium
20
21
  module Core
@@ -22,12 +23,12 @@ module Appium
22
23
  class Driver < ::Selenium::WebDriver::Driver
23
24
  include ::Selenium::WebDriver::DriverExtensions::UploadsFiles
24
25
  include ::Selenium::WebDriver::DriverExtensions::HasSessionId
25
- include ::Selenium::WebDriver::DriverExtensions::Rotatable
26
26
  include ::Selenium::WebDriver::DriverExtensions::HasRemoteStatus
27
27
  include ::Selenium::WebDriver::DriverExtensions::HasWebStorage
28
28
 
29
+ include ::Appium::Core::Base::Rotatable
29
30
  include ::Appium::Core::Base::SearchContext
30
- include ::Appium::Core::Base::TakeScreenshot
31
+ include ::Appium::Core::Base::TakesScreenshot
31
32
 
32
33
  # Private API.
33
34
  # Do not use this for general use. Used by flutter driver to get bridge for creating a new element
@@ -58,6 +59,7 @@ module Appium
58
59
  # Update +server_url+ and HTTP clients following this arguments, protocol, host, port and path.
59
60
  # After this method, +@bridge.http+ will be a new instance following them instead of +server_url+ which is
60
61
  # set before creating session.
62
+ # If +@bridge.http+ did not have +update_sending_request_to+ method, this method returns immediately.
61
63
  #
62
64
  # @example
63
65
  #
@@ -66,10 +68,16 @@ module Appium
66
68
  # driver.manage.timeouts.implicit_wait = 10 # @bridge.http is for 'https://example2.com:9000/wd/hub/'
67
69
  #
68
70
  def update_sending_request_to(protocol:, host:, port:, path:)
69
- @bridge.http.update_sending_request_to(scheme: protocol,
70
- host: host,
71
- port: port,
72
- path: path)
71
+ unless @bridge.http&.class&.method_defined? :update_sending_request_to
72
+ ::Appium::Logger.fatal "#{@bridge.http&.class} has no 'update_sending_request_to'. " \
73
+ 'It keeps current connection target.'
74
+ return
75
+ end
76
+
77
+ @bridge.http&.update_sending_request_to(scheme: protocol,
78
+ host: host,
79
+ port: port,
80
+ path: path)
73
81
  end
74
82
 
75
83
  ### Methods for Appium
@@ -239,6 +247,8 @@ module Appium
239
247
 
240
248
  # Returns an instance of DeviceIME
241
249
  #
250
+ # @return [Appium::Core::Base::Driver::DeviceIME]
251
+ #
242
252
  # @example
243
253
  #
244
254
  # @driver.ime.activate engine: 'com.android.inputmethod.latin/.LatinIME'
@@ -289,6 +299,8 @@ module Appium
289
299
  # @!method ime_activated
290
300
  # Android only. Indicates whether IME input is active at the moment (not if it is available).
291
301
  #
302
+ # @return [Boolean]
303
+ #
292
304
  # @example
293
305
  #
294
306
  # @driver.ime_activated #=> True if IME is activated
@@ -311,6 +323,7 @@ module Appium
311
323
 
312
324
  # Perform a block within the given context, then switch back to the starting context.
313
325
  # @param [String] context The context to switch to for the duration of the block.
326
+ # @param [Proc] block The block to involve within the context
314
327
  #
315
328
  # @example
316
329
  #
@@ -318,8 +331,8 @@ module Appium
318
331
  # @driver.find_element :tag, "button"
319
332
  # end # The result of 'find_element :tag, "button"'
320
333
  #
321
- def within_context(context)
322
- block_given? ? @bridge.within_context(context, &Proc.new) : @bridge.within_context(context)
334
+ def within_context(context, &block)
335
+ block_given? ? @bridge.within_context(context, &block) : @bridge.within_context(context)
323
336
  end
324
337
 
325
338
  # Change to the default context. This is equivalent to +set_context nil+.
@@ -852,7 +865,7 @@ module Appium
852
865
  end
853
866
 
854
867
  # Get the device window's logs.
855
- # @return [String]
868
+ # @return [Appium::Core::Logs]
856
869
  #
857
870
  # @example
858
871
  #
@@ -878,7 +891,7 @@ module Appium
878
891
  # Retrieve the capabilities of the specified session.
879
892
  # It's almost same as +@driver.capabilities+ but you can get more details.
880
893
  #
881
- # @return [Selenium::WebDriver::Remote::Capabilities]
894
+ # @return [Selenium::WebDriver::Remote::Capabilities, Selenium::WebDriver::Remote::W3C::Capabilities]
882
895
  #
883
896
  # @example
884
897
  # @driver.session_capabilities
@@ -1037,7 +1050,7 @@ module Appium
1037
1050
  #
1038
1051
  # @param [String] img_path A path to a partial image you'd like to find
1039
1052
  #
1040
- # @return [::Selenium::WebDriver::Element]
1053
+ # @return [Array<Selenium::WebDriver::Element>]
1041
1054
  #
1042
1055
  # @example
1043
1056
  #
@@ -36,7 +36,8 @@ module Appium
36
36
 
37
37
  attr_reader :additional_headers
38
38
 
39
- def initialize(open_timeout: nil, read_timeout: nil)
39
+ # override
40
+ def initialize(open_timeout: nil, read_timeout: nil) # rubocop:disable Lint/MissingSuper
40
41
  @open_timeout = open_timeout
41
42
  @read_timeout = read_timeout
42
43
  @additional_headers = {}
@@ -54,8 +55,6 @@ module Appium
54
55
  def update_sending_request_to(scheme:, host:, port:, path:)
55
56
  return @server_url unless validate_url_param(scheme, host, port, path)
56
57
 
57
- ::Appium::Logger.debug("[experimental] This feature, #{__method__}, is an experimental")
58
-
59
58
  # Add / if 'path' does not have it
60
59
  path = path.start_with?('/') ? path : "/#{path}"
61
60
  path = path.end_with?('/') ? path : "#{path}/"
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Appium
16
+ module Core
17
+ class Base
18
+ #
19
+ # @api private
20
+ #
21
+
22
+ module Rotatable
23
+ ORIENTATIONS = %i[landscape portrait].freeze
24
+
25
+ #
26
+ # Change the screen orientation
27
+ #
28
+ # @param [:landscape, :portrait] orientation
29
+ #
30
+ #
31
+ def rotation=(orientation)
32
+ unless ORIENTATIONS.include?(orientation)
33
+ raise ArgumentError, "expected #{ORIENTATIONS.inspect}, got #{orientation.inspect}"
34
+ end
35
+
36
+ bridge.screen_orientation = orientation.to_s.upcase
37
+ end
38
+ alias rotate rotation=
39
+
40
+ #
41
+ # Get the current screen orientation
42
+ #
43
+ # @return [:landscape, :portrait] orientation
44
+ #
45
+ # @api public
46
+ #
47
+
48
+ def orientation
49
+ bridge.screen_orientation.to_sym.downcase
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -15,7 +15,7 @@
15
15
  module Appium
16
16
  module Core
17
17
  class Base
18
- module TakeScreenshot
18
+ module TakesScreenshot
19
19
  #
20
20
  # Save a PNG screenshot to the given path
21
21
  #
@@ -18,7 +18,6 @@ module Appium
18
18
  module SearchContext
19
19
  # referenced: ::Selenium::WebDriver::SearchContext
20
20
 
21
- # rubocop:disable Layout/AlignHash
22
21
  FINDERS = ::Selenium::WebDriver::SearchContext::FINDERS.merge(
23
22
  accessibility_id: 'accessibility id',
24
23
  image: '-image',
@@ -37,9 +36,8 @@ module Appium
37
36
  # Tizen with Tizen prefix
38
37
  tizen_uiautomation: '-tizen uiautomation'
39
38
  )
40
- # rubocop:enable Layout/AlignHash
41
39
 
42
- # rubocop:disable Metrics/LineLength
40
+ # rubocop:disable Layout/LineLength
43
41
  #
44
42
  # Find the first element matching the given arguments
45
43
  #
@@ -129,7 +127,7 @@ module Appium
129
127
  # # For Tizen
130
128
  # @driver.find_elements :tizen_uiautomation, '....'
131
129
  #
132
- # rubocop:enable Metrics/LineLength
130
+ # rubocop:enable Layout/LineLength
133
131
  def find_element(*args)
134
132
  how, what = extract_args(args)
135
133
  by = _set_by_from_finders(how)
@@ -143,6 +141,8 @@ module Appium
143
141
  #
144
142
  # Find all elements matching the given arguments
145
143
  #
144
+ # @return [Array<Selenium::WebDriver::Element>]
145
+ #
146
146
  # @see SearchContext#find_elements
147
147
  #
148
148
  def find_elements(*args)
@@ -12,7 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # rubocop:disable Layout/AlignHash
16
15
  module Appium
17
16
  module Core
18
17
  # ref: https://github.com/appium/appium-base-driver/blob/master/lib/mjsonwp/routes.js
@@ -109,4 +108,3 @@ module Appium
109
108
  end # module Commands
110
109
  end # module Core
111
110
  end # module Appium
112
- # rubocop:enable Layout/AlignHash
@@ -12,7 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # rubocop:disable Layout/AlignHash
16
15
  module Appium
17
16
  module Core
18
17
  module Commands
@@ -27,4 +26,3 @@ module Appium
27
26
  end # module Commands
28
27
  end # module Core
29
28
  end # Appium
30
- # rubocop:enable Layout/AlignHash
@@ -12,7 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # rubocop:disable Layout/AlignHash
16
15
  module Appium
17
16
  module Core
18
17
  module Commands
@@ -55,4 +54,3 @@ module Appium
55
54
  end # module Commands
56
55
  end # module Core
57
56
  end # module Appium
58
- # rubocop:enable Layout/AlignHash
@@ -34,7 +34,7 @@ module Appium
34
34
  execute :app_strings, {}, opts
35
35
  end
36
36
 
37
- def background_app(duration = 0) # rubocop:disable Lint/UnusedMethodArgument
37
+ def background_app(duration = 0)
38
38
  # Should override in each driver
39
39
  raise NotImplementedError
40
40
  end
@@ -47,7 +47,7 @@ module Appium
47
47
  # not available in the default OpenCV installation and have to be enabled manually
48
48
  # before library compilation. The default detector name is 'ORB'.
49
49
  # @param [String] match_func The name of the matching function. The default one is 'BruteForce'.
50
- # @param [String] good_matches_factor The maximum count of "good" matches (e. g. with minimal distances).
50
+ # @param [String, nil] good_matches_factor The maximum count of "good" matches (e. g. with minimal distances).
51
51
  # The default one is nil.
52
52
  # @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of
53
53
  # the corresponding picture matching operation. This option is disabled by default.
@@ -94,7 +94,7 @@ module Appium
94
94
  # are supported.
95
95
  # @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of
96
96
  # the corresponding picture matching operation. This option is disabled by default.
97
- # @param [Float] threshold [0.5] At what normalized threshold to reject
97
+ # @param [Float, nil] threshold [0.5] At what normalized threshold to reject
98
98
  #
99
99
  # @example
100
100
  # @driver.find_image_occurrence full_image: "image data 1", partial_image: "image data 2"
@@ -144,7 +144,7 @@ module Appium
144
144
  # +:matchFeatures is by default.
145
145
  # @param [String] first_image An image data. All image formats, that OpenCV library itself accepts, are supported.
146
146
  # @param [String] second_image An image data. All image formats, that OpenCV library itself accepts, are supported.
147
- # @param [Hash] options The content of this dictionary depends on the actual +mode+ value.
147
+ # @param [Hash, nil] options The content of this dictionary depends on the actual +mode+ value.
148
148
  # See the documentation on +appium-support+ module for more details.
149
149
  # @return [Hash] The content of the resulting dictionary depends on the actual +mode+ and +options+ values.
150
150
  # See the documentation on +appium-support+ module for more details.
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Appium
16
+ module Core
17
+ class Base
18
+ module Device
19
+ module Orientation
20
+ def screen_orientation=(orientation)
21
+ execute :set_screen_orientation, {}, { orientation: orientation }
22
+ end
23
+
24
+ def screen_orientation
25
+ execute :get_screen_orientation
26
+ end
27
+ end # module Orientation
28
+ end # module Device
29
+ end # class Base
30
+ end # module Core
31
+ end # module Appium
@@ -53,7 +53,7 @@ module Appium
53
53
  return yield(object)
54
54
  rescue ::Errno::ECONNREFUSED => e
55
55
  raise e
56
- rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions
56
+ rescue *ignored => last_error
57
57
  # swallowed
58
58
  end
59
59
  sleep interval
@@ -98,7 +98,7 @@ module Appium
98
98
  return result if result
99
99
  rescue ::Errno::ECONNREFUSED => e
100
100
  raise e
101
- rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions
101
+ rescue *ignored => last_error
102
102
  # swallowed
103
103
  end
104
104
  sleep interval