testa_appium_driver 0.1.31 → 0.1.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65be3b1fd729bc6fae7bd56227ac9fd4e2167b0e132657ac19e40a0ad184adcf
4
- data.tar.gz: bceb63d4ee18a492482d0b45ed41167a655cff3e565443fafeabf489672bcea2
3
+ metadata.gz: 593c2444720244c32d1a237a40ed80b3f864595bd5f1f5a197fbf87790b0b8af
4
+ data.tar.gz: 5da6b35f561eb2deae604705957ce8a220f4d5dd940728188d67096c9c6c3a7b
5
5
  SHA512:
6
- metadata.gz: 2ac6d2ae6a120827a412f1ce018bef76d50080538607588cae5240db1cedc4d52599b13e6a4c1e7150f2d607495a76e890e0154a6abae147b501b6b22a69b5f0
7
- data.tar.gz: 9dce5768f0f217de3ab7730a7b3d5645d66a5cbc0cb326f71c6df8cc9dca2d23351fb80661e52d6782d07f3e5f01fbfe21f8e56bf39f58ee954a73154e055f12
6
+ metadata.gz: 142dbf94253246348e3802542de308034ba5286286824411d5ae5b711147e5201817bac6951c77286c7a52dd6f4c36d408aa474db860189484535b195846ea89
7
+ data.tar.gz: 1918230241d2f531bffb5205125dff3cafff25b3d997b219807a1e860ccb34d0ee41082ef4a954c5481101a77885e691364d295d2dee9e580ab730a00ac676a1
@@ -1,7 +1,7 @@
1
1
  module TestaAppiumDriver
2
2
  module Attributes
3
3
 
4
- #noinspection RubyNilAnalysis
4
+ # noinspection RubyNilAnalysis
5
5
  def testa_attribute(name, *args)
6
6
  if self.instance_of?(::Selenium::WebDriver::Element) || self.instance_of?(::Appium::Core::Element)
7
7
  @driver = get_driver # does not get correct driver
@@ -10,13 +10,19 @@ module TestaAppiumDriver
10
10
  elements = execute(*args)
11
11
  raise "Element not found" if elements.nil?
12
12
  end
13
-
13
+
14
14
  if elements.kind_of?(::Selenium::WebDriver::Element) || elements.kind_of?(::Appium::Core::Element)
15
- r = elements.send(:attribute, name.to_s)
16
- r = TestaAppiumDriver::Bounds.from_android(r, @driver) if name.to_s == "bounds"
15
+ if name.to_sym == :bounds
16
+ refresh_element = elements.find_element(xpath: ".")
17
+ r = TestaAppiumDriver::Bounds.from_android(refresh_element.send(:attribute, name), @driver)
18
+ else
19
+ r = elements.send(:attribute, name.to_s)
20
+ end
17
21
  else
22
+ # refreshing each element in collection would be too slow
23
+ # ignore the possibility that the bounds could be stale
18
24
  r = elements.map { |e| e.send(:attribute, name.to_s) }
19
- r.map! { |b| TestaAppiumDriver::Bounds.from_android(b, @driver) } if name.to_s == "bounds"
25
+ r.map! { |b| TestaAppiumDriver::Bounds.from_android(b, @driver) } if name.to_sym == :bounds
20
26
  end
21
27
  r
22
28
  end
@@ -101,7 +107,7 @@ module TestaAppiumDriver
101
107
  class Locator
102
108
 
103
109
  # element index in parent element, starts from 0
104
- #noinspection RubyNilAnalysis,RubyYardReturnMatch
110
+ # noinspection RubyNilAnalysis,RubyYardReturnMatch
105
111
  # @return [Integer, nil] index of element
106
112
  def index(*args)
107
113
  raise "Index not supported for uiautomator strategy" if @strategy == FIND_STRATEGY_UIAUTOMATOR
@@ -9,4 +9,4 @@ module ::Appium
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -8,7 +8,6 @@ module TestaAppiumDriver
8
8
  attr_reader :height
9
9
  attr_reader :offset
10
10
 
11
-
12
11
  # @param top_left [Coordinates]
13
12
  # @param bottom_right [Coordinates]
14
13
  # @param window_width [Integer]
@@ -19,7 +18,7 @@ module TestaAppiumDriver
19
18
  @width = bottom_right.x - top_left.x
20
19
  @height = bottom_right.y - top_left.y
21
20
  @offset = Offset.new(self, window_width, window_height)
22
- @center = TestaAppiumDriver::Coordinates.new(@top_left.x + @width/2, @top_left.y + @height / 2)
21
+ @center = TestaAppiumDriver::Coordinates.new(@top_left.x + @width / 2, @top_left.y + @height / 2)
23
22
  end
24
23
 
25
24
  def as_json
@@ -28,7 +27,7 @@ module TestaAppiumDriver
28
27
  height: @height,
29
28
  top_left: @top_left.as_json,
30
29
  bottom_right: @bottom_right.as_json,
31
- offset: @offset.as_json
30
+ offset: @offset.as_json,
32
31
  }
33
32
  end
34
33
 
@@ -41,6 +40,7 @@ module TestaAppiumDriver
41
40
  def top_left
42
41
  @top_left
43
42
  end
43
+
44
44
  # @return [TestaAppiumDriver::Coordinates]
45
45
  def bottom_right
46
46
  @bottom_right
@@ -51,8 +51,12 @@ module TestaAppiumDriver
51
51
  @center
52
52
  end
53
53
 
54
+ def ai
55
+ as_json.ai
56
+ end
57
+
54
58
  def to_s
55
- JSON.dump(as_json)
59
+ "[#{@top_left.x}, #{@top_left.y}][#{@bottom_right.x}, #{@bottom_right.y}]"
56
60
  end
57
61
 
58
62
  # @param bounds [String] bounds that driver.attribute("bounds") return
@@ -81,7 +85,7 @@ module TestaAppiumDriver
81
85
  end
82
86
  end
83
87
 
84
- #noinspection ALL
88
+ # noinspection ALL
85
89
  class Coordinates
86
90
  def initialize(x, y)
87
91
  @x = x.to_i
@@ -95,7 +99,6 @@ module TestaAppiumDriver
95
99
  }
96
100
  end
97
101
 
98
-
99
102
  # @return [Integer]
100
103
  def x
101
104
  @x
@@ -107,7 +110,6 @@ module TestaAppiumDriver
107
110
  end
108
111
  end
109
112
 
110
-
111
113
  class Offset
112
114
  def initialize(bounds, window_width, window_height)
113
115
  @top = bounds.top_left.y
@@ -125,7 +127,6 @@ module TestaAppiumDriver
125
127
  }
126
128
  end
127
129
 
128
-
129
130
  # @return [Integer]
130
131
  def top
131
132
  @top
@@ -147,4 +148,4 @@ module TestaAppiumDriver
147
148
  end
148
149
 
149
150
  end
150
- end
151
+ end
@@ -67,14 +67,13 @@ 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, bounds_from_cache_element: true)
70
+ def align(with = :top, top: nil, bottom: nil, right: nil, left: nil, scroll_to_find: false, max_attempts: 3)
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,
77
- bounds_from_cache_element: bounds_from_cache_element)
76
+ default_scroll_strategy: @default_scroll_strategy)
78
77
  sa.align(with, scroll_to_find, max_attempts)
79
78
  self
80
79
  end
@@ -84,8 +83,8 @@ module TestaAppiumDriver
84
83
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
85
84
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
86
85
  # @return [TestaAppiumDriver::Locator]
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)
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)
89
88
  end
90
89
 
91
90
  # Aligns element on bottom of the scrollable container, if the element does not exists it will scroll to find it
@@ -93,8 +92,8 @@ module TestaAppiumDriver
93
92
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
94
93
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
95
94
  # @return [TestaAppiumDriver::Locator]
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)
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)
98
97
  end
99
98
 
100
99
  # Aligns element on left of the scrollable container, if the element does not exists it will scroll to find it
@@ -102,8 +101,8 @@ module TestaAppiumDriver
102
101
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
103
102
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
104
103
  # @return [TestaAppiumDriver::Locator]
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)
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)
107
106
  end
108
107
 
109
108
  # Aligns element on right of the scrollable container, if the element does not exists it will scroll to find it
@@ -111,8 +110,8 @@ module TestaAppiumDriver
111
110
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
112
111
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
113
112
  # @return [TestaAppiumDriver::Locator]
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)
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)
116
115
  end
117
116
 
118
117
  # Aligns element (by default) on top of the scrollable container, if the element does not exists it raise an exception
@@ -120,8 +119,8 @@ module TestaAppiumDriver
120
119
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
121
120
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
122
121
  # @return [TestaAppiumDriver::Locator]
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)
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)
125
124
  end
126
125
 
127
126
  # Aligns element on top of the scrollable container, if the element does not exists it raise an exception
@@ -129,8 +128,8 @@ module TestaAppiumDriver
129
128
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
130
129
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
131
130
  # @return [TestaAppiumDriver::Locator]
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)
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)
134
133
  end
135
134
 
136
135
  # Aligns element on bottom of the scrollable container, if the element does not exists it raise an exception
@@ -138,8 +137,8 @@ module TestaAppiumDriver
138
137
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
139
138
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
140
139
  # @return [TestaAppiumDriver::Locator]
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)
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)
143
142
  end
144
143
 
145
144
  # Aligns element on left of the scrollable container, if the element does not exists it raise an exception
@@ -147,8 +146,8 @@ module TestaAppiumDriver
147
146
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
148
147
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
149
148
  # @return [TestaAppiumDriver::Locator]
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)
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)
152
151
  end
153
152
 
154
153
  # Aligns element on right of the scrollable container, if the element does not exists it raise an exception
@@ -156,8 +155,8 @@ module TestaAppiumDriver
156
155
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
157
156
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
158
157
  # @return [TestaAppiumDriver::Locator]
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)
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)
161
160
  end
162
161
 
163
162
  # First scrolls to the beginning of the scrollable container and then scrolls down until element is found or end is reached
@@ -270,7 +269,12 @@ module TestaAppiumDriver
270
269
  end
271
270
 
272
271
  if to.kind_of?(::Selenium::WebDriver::Element) || to.kind_of?(::Appium::Core::Element)
273
- bounds = TestaAppiumDriver::Bounds.from_android(to.bounds, @driver)
272
+ if @driver.device == :android
273
+ bounds = TestaAppiumDriver::Bounds.from_android(to.bounds, @driver)
274
+ else
275
+ bounds = TestaAppiumDriver::Bounds.from_ios(to.bounds, @driver)
276
+ end
277
+
274
278
  x = bounds.center.x
275
279
  y = bounds.center.y
276
280
  end
@@ -309,6 +313,7 @@ module TestaAppiumDriver
309
313
  end
310
314
 
311
315
  private
316
+
312
317
  def _process_deadzone(top, bottom, right, left)
313
318
  deadzone = nil
314
319
  if !top.nil? || !bottom.nil? || !right.nil? || !left.nil?
@@ -187,7 +187,8 @@ module ::TestaAppiumDriver
187
187
  begin
188
188
  r = execute(skip_cache: true, ignore_implicit_wait: true)
189
189
  return r.count.positive? if r.is_a?(Array)
190
- return r.displayed? if @driver.ios?
190
+ # ios17 has phantom child elements that overlap parent so this returns false positive
191
+ # return r.displayed? if @driver.ios?
191
192
  rescue StandardError
192
193
  found = false
193
194
  end
@@ -332,56 +333,51 @@ module ::TestaAppiumDriver
332
333
  # if both x or y, or both are not given, will click in the center of the element
333
334
  # @param x If positive integer, will offset the click from the left side, if negative integer, will offset the click from the right. If float value is given, it will threat it as percentage offset, giving it 0.5 will click in the middle
334
335
  # @param y If positive integer, will offset the click from the bottom side, if negative integer, will offset the click from the top. If float value is given, it will threat it as percentage offset, giving it 0.5 will click in the middle
335
- def click(x = nil, y = nil, double: false, by_coords: false)
336
- if !x.nil? && !y.nil? || double || by_coords
337
-
338
- x = 0.5 if x.nil?
339
- y = 0.5 if y.nil?
340
-
341
- b = self.bounds
342
- if x.is_a?(Integer)
343
- if x >= 0
344
- x = b.top_left.x + x
345
- else
346
- x = b.bottom_right.x + x
347
- end
348
- elsif x.is_a?(Float) && x <= 1.0 && x >= 0
349
- x = b.top_left.x + b.width * x
336
+ def click(x = nil, y = nil, double: false)
337
+ x = 0.5 if x.nil?
338
+ y = 0.5 if y.nil?
339
+
340
+ b = self.bounds
341
+ if x.is_a?(Integer)
342
+ if x >= 0
343
+ x = b.top_left.x + x
350
344
  else
351
- raise "x value #{x} not supported. Use integer as pixel or float (0..1) as percentage of element width"
345
+ x = b.bottom_right.x + x
352
346
  end
347
+ elsif x.is_a?(Float) && x <= 1.0 && x >= 0
348
+ x = b.top_left.x + b.width * x
349
+ else
350
+ raise "x value #{x} not supported. Use integer as pixel or float (0..1) as percentage of element width"
351
+ end
353
352
 
354
- if y.is_a?(Integer)
355
- if y >= 0
356
- y = b.top_left.y + y
357
- else
358
- y = b.bottom_right + y
359
- end
360
- elsif y.is_a?(Float) && y <= 1.0 && y >= 0
361
- y = b.top_left.y + b.height * y
353
+ if y.is_a?(Integer)
354
+ if y >= 0
355
+ y = b.top_left.y + y
362
356
  else
363
- raise "y value #{x} not supported. Use integer as pixel or float (0..1) as percentage of element height"
357
+ y = b.bottom_right + y
364
358
  end
359
+ elsif y.is_a?(Float) && y <= 1.0 && y >= 0
360
+ y = b.top_left.y + b.height * y
361
+ else
362
+ raise "y value #{x} not supported. Use integer as pixel or float (0..1) as percentage of element height"
363
+ end
365
364
 
366
- action_builder = @driver.action
367
- f1 = action_builder.add_pointer_input(:touch, "finger1")
368
- f1.create_pointer_move(duration: 0.1, x: x, y: y, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
365
+ action_builder = @driver.action
366
+ f1 = action_builder.add_pointer_input(:touch, "finger1")
367
+ f1.create_pointer_move(duration: 0.1, x: x, y: y, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
368
+ f1.create_pointer_down(:left)
369
+ f1.create_pointer_up(:left)
370
+ if double
371
+ if @driver.ios?
372
+ # NOTE: ios is stupid, we have to do another move
373
+ # NOTE: ios is stupid, works very wierd if duration is 0
374
+ f1.create_pointer_move(duration: 0.1, x: x, y: y, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
375
+ end
376
+ f1.create_pause(0.1)
369
377
  f1.create_pointer_down(:left)
370
378
  f1.create_pointer_up(:left)
371
- if double
372
- if @driver.ios?
373
- # NOTE: ios is stupid, we have to do another move
374
- # NOTE: ios is stupid, works very wierd if duration is 0
375
- f1.create_pointer_move(duration: 0.1, x: x, y: y, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
376
- end
377
- f1.create_pause(0.1)
378
- f1.create_pointer_down(:left)
379
- f1.create_pointer_up(:left)
380
- end
381
- @driver.perform_actions [f1]
382
- else
383
- perform_driver_method(:click)
384
379
  end
380
+ @driver.perform_actions [f1]
385
381
  end
386
382
 
387
383
  alias_method :tap, :click
@@ -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)
@@ -207,25 +207,25 @@ module ::TestaAppiumDriver
207
207
  when :top
208
208
  y0 = @bounds.bottom_right.y - @deadzone[:bottom]
209
209
  y1 = y0 - @align_offset
210
- x0 = @bounds.width / 2
210
+ x0 = @bounds.center.x
211
211
  x1 = x0
212
212
  scroll_direction = :down
213
213
  when :bottom
214
214
  y0 = @bounds.top_left.y + @deadzone[:top]
215
215
  y1 = y0 + @align_offset
216
- x0 = @bounds.width / 2
216
+ x0 = @bounds.center.x
217
217
  x1 = x0
218
218
  scroll_direction = :up
219
219
  when :left
220
220
  x0 = @bounds.bottom_right.x - @deadzone[:right]
221
221
  x1 = x0 - @align_offset
222
- y0 = @bounds.height / 2
222
+ y0 = @bounds.center.y
223
223
  y1 = y0
224
224
  scroll_direction = :right
225
225
  when :right
226
226
  x0 = @bounds.top_left.x + @deadzone[:top]
227
227
  x1 = x0 + @align_offset
228
- y0 = @bounds.height / 2
228
+ y0 = @bounds.center.y
229
229
  y1 = y0
230
230
  scroll_direction = :left
231
231
  else
@@ -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,7 +16,6 @@ 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
20
19
  def initialize(scrollable, params = {})
21
20
  @scrollable = scrollable
22
21
  @locator = params[:locator]
@@ -24,9 +23,6 @@ module ::TestaAppiumDriver
24
23
  @deadzone = params[:deadzone]
25
24
  @max_scrolls = params[:max_scrolls]
26
25
  @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
-
30
26
  @driver = @locator.driver
31
27
 
32
28
  if @scrollable.nil?
@@ -205,20 +201,7 @@ module ::TestaAppiumDriver
205
201
  end
206
202
 
207
203
  def is_aligned?(with, 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)
204
+ align_bounds = @locator.bounds(force_cache_element: element)
222
205
  case with
223
206
  when :top
224
207
  @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.31
4
+ version: 0.1.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - karlo.razumovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-25 00:00:00.000000000 Z
11
+ date: 2024-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appium_lib_core
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: json
29
43
  requirement: !ruby/object:Gem::Requirement