testa_appium_driver 0.1.30 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3521033bcda4e9b61fd523c8aa716c6bcfd99dc9e2ff820bf823adea8f4582c0
4
- data.tar.gz: 2443236705abef799f76de8a03db745b972f3ff9092b9b19a689a20aba329c21
3
+ metadata.gz: 65be3b1fd729bc6fae7bd56227ac9fd4e2167b0e132657ac19e40a0ad184adcf
4
+ data.tar.gz: bceb63d4ee18a492482d0b45ed41167a655cff3e565443fafeabf489672bcea2
5
5
  SHA512:
6
- metadata.gz: 6648e41a86d22e367bfef3b77d9db4ae5381b2bd5d787a875d2f77d8c842c7bcc4b65a450d608bbe7a0b006af47ab0fe21ccb120cb26b9c8e1f2f441c7f22d02
7
- data.tar.gz: edd62bab2c971aa7334bf2521a9a5c91447a8892e94a1834a74c7e09fb69368c5c3b91b9d2bea20c14c9f5b36a751dc85932896b4c4b917db0cb44a4f34f570c
6
+ metadata.gz: 2ac6d2ae6a120827a412f1ce018bef76d50080538607588cae5240db1cedc4d52599b13e6a4c1e7150f2d607495a76e890e0154a6abae147b501b6b22a69b5f0
7
+ data.tar.gz: 9dce5768f0f217de3ab7730a7b3d5645d66a5cbc0cb326f71c6df8cc9dca2d23351fb80661e52d6782d07f3e5f01fbfe21f8e56bf39f58ee954a73154e055f12
data/Gemfile CHANGED
@@ -9,5 +9,5 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- gem "rubocop", "~> 1.26.0", require: false
12
+ gem "rubocop", require: false
13
13
  gem "rubocop-performance", require: false
@@ -67,13 +67,14 @@ module TestaAppiumDriver
67
67
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
68
68
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
69
69
  # @return [TestaAppiumDriver::Locator]
70
- def align(with = :top, top: nil, bottom: nil, right: nil, left: nil, scroll_to_find: false, max_attempts: 3)
70
+ def align(with = :top, top: nil, bottom: nil, right: nil, left: nil, scroll_to_find: false, max_attempts: 3, bounds_from_cache_element: true)
71
71
  deadzone = _process_deadzone(top, bottom, right, left)
72
72
  deadzone = @scrollable_locator.scroll_deadzone if deadzone.nil? && !@scrollable_locator.nil?
73
73
  sa = ScrollActions.new(@scrollable_locator,
74
74
  locator: self,
75
75
  deadzone: deadzone,
76
- default_scroll_strategy: @default_scroll_strategy)
76
+ default_scroll_strategy: @default_scroll_strategy,
77
+ bounds_from_cache_element: bounds_from_cache_element)
77
78
  sa.align(with, scroll_to_find, max_attempts)
78
79
  self
79
80
  end
@@ -83,8 +84,8 @@ module TestaAppiumDriver
83
84
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
84
85
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
85
86
  # @return [TestaAppiumDriver::Locator]
86
- def align_top(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
87
- align(:top, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts)
87
+ def align_top(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
88
+ align(:top, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
88
89
  end
89
90
 
90
91
  # Aligns element on bottom of the scrollable container, if the element does not exists it will scroll to find it
@@ -92,8 +93,8 @@ module TestaAppiumDriver
92
93
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
93
94
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
94
95
  # @return [TestaAppiumDriver::Locator]
95
- def align_bottom(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
96
- align(:bottom, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts)
96
+ def align_bottom(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
97
+ align(:bottom, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
97
98
  end
98
99
 
99
100
  # Aligns element on left of the scrollable container, if the element does not exists it will scroll to find it
@@ -101,8 +102,8 @@ module TestaAppiumDriver
101
102
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
102
103
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
103
104
  # @return [TestaAppiumDriver::Locator]
104
- def align_left(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
105
- align(:left, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts)
105
+ def align_left(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
106
+ align(:left, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
106
107
  end
107
108
 
108
109
  # Aligns element on right of the scrollable container, if the element does not exists it will scroll to find it
@@ -110,8 +111,8 @@ module TestaAppiumDriver
110
111
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
111
112
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
112
113
  # @return [TestaAppiumDriver::Locator]
113
- def align_right(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
114
- align(:right, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts)
114
+ def align_right(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
115
+ align(:right, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
115
116
  end
116
117
 
117
118
  # Aligns element (by default) on top of the scrollable container, if the element does not exists it raise an exception
@@ -119,8 +120,8 @@ module TestaAppiumDriver
119
120
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
120
121
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
121
122
  # @return [TestaAppiumDriver::Locator]
122
- def align!(with = :top, top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
123
- align(with, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
123
+ def align!(with = :top, top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
124
+ align(with, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
124
125
  end
125
126
 
126
127
  # Aligns element on top of the scrollable container, if the element does not exists it raise an exception
@@ -128,8 +129,8 @@ module TestaAppiumDriver
128
129
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
129
130
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
130
131
  # @return [TestaAppiumDriver::Locator]
131
- def align_top!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
132
- align(:top, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
132
+ def align_top!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
133
+ align(:top, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
133
134
  end
134
135
 
135
136
  # Aligns element on bottom of the scrollable container, if the element does not exists it raise an exception
@@ -137,8 +138,8 @@ module TestaAppiumDriver
137
138
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
138
139
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
139
140
  # @return [TestaAppiumDriver::Locator]
140
- def align_bottom!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
141
- align(:bottom, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
141
+ def align_bottom!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
142
+ align(:bottom, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
142
143
  end
143
144
 
144
145
  # Aligns element on left of the scrollable container, if the element does not exists it raise an exception
@@ -146,8 +147,8 @@ module TestaAppiumDriver
146
147
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
147
148
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
148
149
  # @return [TestaAppiumDriver::Locator]
149
- def align_left!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
150
- align(:left, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
150
+ def align_left!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
151
+ align(:left, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
151
152
  end
152
153
 
153
154
  # Aligns element on right of the scrollable container, if the element does not exists it raise an exception
@@ -155,8 +156,8 @@ module TestaAppiumDriver
155
156
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
156
157
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
157
158
  # @return [TestaAppiumDriver::Locator]
158
- def align_right!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
159
- align(:right, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
159
+ def align_right!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3, bounds_from_cache_element: true)
160
+ align(:right, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts, bounds_from_cache_element: bounds_from_cache_element)
160
161
  end
161
162
 
162
163
  # First scrolls to the beginning of the scrollable container and then scrolls down until element is found or end is reached
@@ -186,7 +186,7 @@ module ::TestaAppiumDriver
186
186
  stale_retries = 0
187
187
  begin
188
188
  until is_aligned?(with, element) || timeout == max_attempts
189
- # $ctx.puts("align roudn: #{timeout}")
189
+ # $ctx.puts("align roudn: #{timeout}")
190
190
  w3c_attempt_align(with, speed_coef)
191
191
  timeout += 1
192
192
  end
@@ -194,12 +194,12 @@ module ::TestaAppiumDriver
194
194
  # if boundElementsByIndex is enabled, we can get stale element reference while doing scroll each
195
195
  stale_retries += 1
196
196
  sleep 0.2
197
- # $ctx.puts "Looking for #{@locator.xpath_selector}"
197
+ # $ctx.puts "Looking for #{@locator.xpath_selector}"
198
198
  element = @locator.execute if @locator.instance_of?(TestaAppiumDriver::Locator)
199
199
  retry if stale_retries < 4
200
200
  raise
201
201
  end
202
- # $ctx.puts("end align")
202
+ # $ctx.puts("end align")
203
203
  end
204
204
 
205
205
  def w3c_attempt_align(with, speed_coef)
@@ -240,9 +240,9 @@ module ::TestaAppiumDriver
240
240
  rounds = 0
241
241
  max_scrolls_reached = false
242
242
  end_of_scroll_reached = false
243
- # $ctx.puts("starting scroll to")
243
+ # $ctx.puts("starting scroll to")
244
244
  until (element_found = ((@driver.android? && @locator.exists?) || (@driver.ios? && @locator.exists? && @locator.in_viewport?))) || end_of_scroll_reached
245
- # $ctx.puts("Scroll to round: #{rounds}")
245
+ # $ctx.puts("Scroll to round: #{rounds}")
246
246
  end_of_scroll_reached = is_end_of_scroll?
247
247
  case direction
248
248
  when :down
@@ -268,7 +268,7 @@ module ::TestaAppiumDriver
268
268
  max_scrolls_reached = true if rounds == @max_scrolls
269
269
  break if rounds == @max_scrolls
270
270
  end
271
- # $ctx.puts("end scroll to")
271
+ # $ctx.puts("end scroll to")
272
272
  raise Selenium::WebDriver::Error::NoSuchElementError if (max_scrolls_reached || end_of_scroll_reached) && !element_found
273
273
  end
274
274
 
@@ -362,8 +362,8 @@ module ::TestaAppiumDriver
362
362
  f1.create_pointer_move(duration: overscroll_pause, x: x1, y: y1, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
363
363
  end
364
364
  f1.create_pointer_up(:left)
365
- puts "Scroll execute[w3c_action]: #{type}: {x0: #{x0}, y0: #{y0}} => (duration: #{duration}) => {x1: #{x1}, y1: #{y1}}"
366
- # $ctx.puts "Scroll execute[w3c_action]: #{type}: {x0: #{x0}, y0: #{y0}} => (duration: #{duration}) => {x1: #{x1}, y1: #{y1}}"
365
+ # puts "Scroll execute[w3c_action]: #{type}: {x0: #{x0}, y0: #{y0}} => (duration: #{duration}) => {x1: #{x1}, y1: #{y1}}"
366
+ # $ctx.puts "Scroll execute[w3c_action]: #{type}: {x0: #{x0}, y0: #{y0}} => (duration: #{duration}) => {x1: #{x1}, y1: #{y1}}"
367
367
  @driver.perform_actions [f1]
368
368
  end
369
369
 
@@ -16,6 +16,7 @@ module ::TestaAppiumDriver
16
16
  # - deadzone - [Hash] that stores top, bottom, left and right deadzone values. If deadzone[:top] is 200 then 200px from top of the scrollable container will not be used for scrolling
17
17
  # - max_scrolls - [Integer] maximum number of scrolls before exception is thrown
18
18
  # - default_scroll_strategy - defines which scroll strategy will be used if a scroll action is valid for multiple strategies
19
+ # - bounds_from_cache_element - true by default, use the cached element to get element bounds
19
20
  def initialize(scrollable, params = {})
20
21
  @scrollable = scrollable
21
22
  @locator = params[:locator]
@@ -23,6 +24,9 @@ module ::TestaAppiumDriver
23
24
  @deadzone = params[:deadzone]
24
25
  @max_scrolls = params[:max_scrolls]
25
26
  @default_scroll_strategy = params[:default_scroll_strategy]
27
+ @bounds_from_cache_element = params[:bounds_from_cache_element]
28
+ @bounds_from_cache_element = true if @bounds_from_cache_element.nil?
29
+
26
30
  @driver = @locator.driver
27
31
 
28
32
  if @scrollable.nil?
@@ -201,7 +205,20 @@ module ::TestaAppiumDriver
201
205
  end
202
206
 
203
207
  def is_aligned?(with, element)
204
- align_bounds = @locator.bounds(force_cache_element: element)
208
+ if @bounds_from_cache_element
209
+ # in some cases, the cached element returns the same bounds, even though it was scrolled a split second ago
210
+ align_bounds = @locator.bounds(force_cache_element: element)
211
+ else
212
+ align_bounds = @locator.bounds
213
+ end
214
+
215
+ # $ctx.puts("Align bounds: ")
216
+ # $ctx.puts(align_bounds)
217
+ # $ctx.puts("Scrollable bounds: ")
218
+ # $ctx.puts(@bounds)
219
+
220
+ # $ctx.puts("Deadzone: ")
221
+ # $ctx.puts(@deadzone)
205
222
  case with
206
223
  when :top
207
224
  @align_offset = align_bounds.top_left.y - @bounds.top_left.y - @deadzone[:top]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testa_appium_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - karlo.razumovic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-06 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appium_lib_core
@@ -90,7 +90,7 @@ metadata:
90
90
  homepage_uri: https://github.com/Karazum/testa_appium_driver
91
91
  source_code_uri: https://github.com/Karazum/testa_appium_driver
92
92
  changelog_uri: https://github.com/Karazum/testa_appium_driver
93
- post_install_message:
93
+ post_install_message:
94
94
  rdoc_options: []
95
95
  require_paths:
96
96
  - lib
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubygems_version: 3.1.6
109
- signing_key:
109
+ signing_key:
110
110
  specification_version: 4
111
111
  summary: Appium made easy
112
112
  test_files: []