testa_appium_driver 0.1.11 → 0.1.12
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 +4 -4
- data/.gitignore +15 -15
- data/.idea/deployment.xml +21 -21
- data/.idea/inspectionProfiles/Project_Default.xml +8 -8
- data/.idea/misc.xml +5 -5
- data/.idea/modules.xml +7 -7
- data/.idea/runConfigurations/Android_Test.xml +41 -41
- data/.idea/runConfigurations.xml +9 -9
- data/.idea/sshConfigs.xml +12 -12
- data/.idea/vcs.xml +5 -5
- data/.idea/webServers.xml +20 -20
- data/.rspec +3 -3
- data/.rubocop.yml +13 -13
- data/CHANGELOG.md +5 -5
- data/CODE_OF_CONDUCT.md +102 -102
- data/Gemfile +12 -12
- data/LICENSE.txt +21 -21
- data/README.md +378 -378
- data/Rakefile +12 -12
- data/bin/console +17 -17
- data/bin/setup +8 -8
- data/lib/testa_appium_driver/android/class_selectors.rb +437 -437
- data/lib/testa_appium_driver/android/driver.rb +69 -69
- data/lib/testa_appium_driver/android/locator/attributes.rb +113 -113
- data/lib/testa_appium_driver/android/locator.rb +141 -141
- data/lib/testa_appium_driver/android/scroll_actions/uiautomator_scroll_actions.rb +61 -61
- data/lib/testa_appium_driver/android/selenium_element.rb +7 -7
- data/lib/testa_appium_driver/common/bounds.rb +149 -149
- data/lib/testa_appium_driver/common/constants.rb +36 -36
- data/lib/testa_appium_driver/common/exceptions/strategy_mix_exception.rb +11 -11
- data/lib/testa_appium_driver/common/helpers.rb +270 -270
- data/lib/testa_appium_driver/common/locator/scroll_actions.rb +397 -397
- data/lib/testa_appium_driver/common/locator.rb +610 -610
- data/lib/testa_appium_driver/common/scroll_actions/json_wire_scroll_actions.rb +3 -3
- data/lib/testa_appium_driver/common/scroll_actions/w3c_scroll_actions.rb +237 -237
- data/lib/testa_appium_driver/common/scroll_actions.rb +246 -246
- data/lib/testa_appium_driver/common/selenium_element.rb +19 -19
- data/lib/testa_appium_driver/driver.rb +312 -312
- data/lib/testa_appium_driver/ios/driver.rb +48 -48
- data/lib/testa_appium_driver/ios/locator/attributes.rb +80 -80
- data/lib/testa_appium_driver/ios/locator.rb +70 -70
- data/lib/testa_appium_driver/ios/selenium_element.rb +6 -6
- data/lib/testa_appium_driver/ios/type_selectors.rb +187 -187
- data/lib/testa_appium_driver/version.rb +5 -5
- data/lib/testa_appium_driver.rb +6 -6
- data/testa_appium_driver.gemspec +41 -41
- data/testa_appium_driver.iml +27 -78
- metadata +3 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
module TestaAppiumDriver
|
2
|
-
class ScrollActions
|
3
|
-
end
|
1
|
+
module TestaAppiumDriver
|
2
|
+
class ScrollActions
|
3
|
+
end
|
4
4
|
end
|
@@ -1,238 +1,238 @@
|
|
1
|
-
module TestaAppiumDriver
|
2
|
-
class ScrollActions
|
3
|
-
|
4
|
-
private
|
5
|
-
# @return [Array]
|
6
|
-
def
|
7
|
-
elements = []
|
8
|
-
begin
|
9
|
-
default_deadzone!
|
10
|
-
|
11
|
-
iterations = 0
|
12
|
-
|
13
|
-
|
14
|
-
if direction.nil?
|
15
|
-
scroll_to_start
|
16
|
-
if @scrollable.scroll_orientation == :vertical
|
17
|
-
direction = :down
|
18
|
-
else
|
19
|
-
direction = :right
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
until is_end_of_scroll?
|
24
|
-
matches = @locator.execute(skip_cache: true)
|
25
|
-
matches.each_with_index do |m|
|
26
|
-
next if elements.include?(m)
|
27
|
-
elements << m
|
28
|
-
if block_given? # block is given
|
29
|
-
block.call(m) # use call to execute the block
|
30
|
-
else # the value of block_argument becomes nil if you didn't give a block
|
31
|
-
# block was not given
|
32
|
-
end
|
33
|
-
end
|
34
|
-
iterations += 1
|
35
|
-
break if !@max_scrolls.nil? && iterations == @max_scrolls
|
36
|
-
self.send("page_#{direction}")
|
37
|
-
end
|
38
|
-
rescue => e
|
39
|
-
raise e
|
40
|
-
|
41
|
-
end
|
42
|
-
elements
|
43
|
-
end
|
44
|
-
|
45
|
-
def w3c_align(with, scroll_to_find)
|
46
|
-
default_deadzone!
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@locator.scroll_to if scroll_to_find
|
51
|
-
|
52
|
-
element = @locator.execute
|
53
|
-
|
54
|
-
timeout = 0
|
55
|
-
until is_aligned?(with, element) || timeout == 3
|
56
|
-
w3c_attempt_align(with)
|
57
|
-
timeout += 1
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
def w3c_attempt_align(with)
|
64
|
-
case with
|
65
|
-
when :top
|
66
|
-
y0 = @bounds.bottom_right.y - @deadzone[:bottom]
|
67
|
-
y1 = y0 - @align_offset
|
68
|
-
x0 = @bounds.width / 2
|
69
|
-
x1 = x0
|
70
|
-
scroll_direction = :down
|
71
|
-
when :bottom
|
72
|
-
y0 = @bounds.top_left.y + @deadzone[:top]
|
73
|
-
y1 = y0 + @align_offset
|
74
|
-
x0 = @bounds.width / 2
|
75
|
-
x1 = x0
|
76
|
-
scroll_direction = :up
|
77
|
-
when :left
|
78
|
-
x0 = @bounds.bottom_right.x - @deadzone[:right]
|
79
|
-
x1 = x0 - @align_offset
|
80
|
-
y0 = @bounds.height / 2
|
81
|
-
y1 = y0
|
82
|
-
scroll_direction = :right
|
83
|
-
when :right
|
84
|
-
x0 = @bounds.top_left.x + @deadzone[:top]
|
85
|
-
x1 = x0 + @align_offset
|
86
|
-
y0 = @bounds.height / 2
|
87
|
-
y1 = y0
|
88
|
-
scroll_direction = :left
|
89
|
-
else
|
90
|
-
raise "Unsupported align with option: #{with}"
|
91
|
-
end
|
92
|
-
|
93
|
-
x1, y1 = apply_w3c_correction(x1, y1, scroll_direction) if @driver.device == :android
|
94
|
-
w3c_action(x0, y0, x1, y1, SCROLL_ACTION_TYPE_SCROLL)
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def w3c_scroll_to(direction)
|
99
|
-
|
100
|
-
rounds = 0
|
101
|
-
max_scrolls_reached = false
|
102
|
-
end_of_scroll_reached = false
|
103
|
-
until @locator.exists? || end_of_scroll_reached
|
104
|
-
end_of_scroll_reached = is_end_of_scroll?
|
105
|
-
case direction
|
106
|
-
when :down
|
107
|
-
page_down
|
108
|
-
when :right
|
109
|
-
page_right
|
110
|
-
when :left
|
111
|
-
page_left
|
112
|
-
when :up
|
113
|
-
page_up
|
114
|
-
else
|
115
|
-
scroll_to_start
|
116
|
-
@previous_elements = nil
|
117
|
-
if @scrollable.scroll_orientation == :vertical
|
118
|
-
direction = :down
|
119
|
-
else
|
120
|
-
direction = :right
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
rounds += 1
|
125
|
-
|
126
|
-
max_scrolls_reached = true if rounds == @max_scrolls
|
127
|
-
break if rounds == @max_scrolls
|
128
|
-
end
|
129
|
-
raise Selenium::WebDriver::Error::NoSuchElementError if max_scrolls_reached || end_of_scroll_reached
|
130
|
-
end
|
131
|
-
|
132
|
-
def w3c_scroll_to_start_or_end(type)
|
133
|
-
default_deadzone!
|
134
|
-
|
135
|
-
@previous_elements = nil
|
136
|
-
|
137
|
-
|
138
|
-
if type == :start
|
139
|
-
if @scrollable.scroll_orientation == :vertical
|
140
|
-
method = "fling_up"
|
141
|
-
else
|
142
|
-
method = "fling_left"
|
143
|
-
end
|
144
|
-
else
|
145
|
-
if @scrollable.scroll_orientation == :vertical
|
146
|
-
method = "fling_down"
|
147
|
-
else
|
148
|
-
method = "fling_right"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
iterations = 0
|
153
|
-
until is_end_of_scroll? || iterations >= 3
|
154
|
-
self.send(method)
|
155
|
-
iterations += 1
|
156
|
-
end
|
157
|
-
|
158
|
-
# reset the flag for end of scroll elements
|
159
|
-
@previous_elements = nil
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
def w3c_page_or_fling(type, direction)
|
164
|
-
default_deadzone!
|
165
|
-
|
166
|
-
if direction == :down || direction == :up
|
167
|
-
if direction == :down
|
168
|
-
y0 = @bounds.bottom_right.y - @deadzone[:bottom].to_i
|
169
|
-
y1 = @bounds.top_left.y + @deadzone[:top].to_i
|
170
|
-
else
|
171
|
-
y0 = @bounds.top_left.y + @deadzone[:top].to_i
|
172
|
-
y1 = @bounds.bottom_right.y - @deadzone[:bottom].to_i
|
173
|
-
end
|
174
|
-
x0 = @bounds.width / 2
|
175
|
-
x1 = x0
|
176
|
-
else
|
177
|
-
if direction == :right
|
178
|
-
x0 = @bounds.bottom_right.x - @deadzone[:right].to_i
|
179
|
-
x1 = @bounds.top_left.x + @deadzone[:left].to_i
|
180
|
-
else
|
181
|
-
x0 = @bounds.top_left.x + @deadzone[:left].to_i
|
182
|
-
x1 = @bounds.bottom_right.x - @deadzone[:right].to_i
|
183
|
-
end
|
184
|
-
y0 = @bounds.height / 2
|
185
|
-
y1 = y0
|
186
|
-
end
|
187
|
-
x1, y1 = apply_w3c_correction(x1, y1, direction) if @driver.device == :android
|
188
|
-
|
189
|
-
|
190
|
-
w3c_action(x0, y0, x1, y1, type)
|
191
|
-
|
192
|
-
end
|
193
|
-
|
194
|
-
|
195
|
-
def w3c_action(x0, y0, x1, y1, type)
|
196
|
-
if type == SCROLL_ACTION_TYPE_SCROLL
|
197
|
-
duration = 1.8
|
198
|
-
elsif type == SCROLL_ACTION_TYPE_FLING
|
199
|
-
duration = 0.1
|
200
|
-
elsif type == SCROLL_ACTION_TYPE_DRAG
|
201
|
-
duration = 3.5
|
202
|
-
else
|
203
|
-
raise "Unknown scroll action type #{type}"
|
204
|
-
end
|
205
|
-
|
206
|
-
action_builder = @driver.action
|
207
|
-
f1 = action_builder.add_pointer_input(:touch, "finger1")
|
208
|
-
f1.create_pointer_move(duration: 0, x: x0, y: y0, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
|
209
|
-
f1.create_pointer_down(:left)
|
210
|
-
|
211
|
-
f1.create_pointer_move(duration: duration, x: x1, y: y1, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
|
212
|
-
unless type == SCROLL_ACTION_TYPE_FLING
|
213
|
-
# with this move we prevent flinging/overscroll
|
214
|
-
f1.create_pointer_move(duration: 0.5, x: x1, y: y1, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
|
215
|
-
end
|
216
|
-
f1.create_pointer_up(:left)
|
217
|
-
puts "Scroll execute[w3c_action]: #{type}: {x0: #{x0}, y0: #{y0}} => {x1: #{x1}, y1: #{y1}}"
|
218
|
-
@driver.perform_actions [f1]
|
219
|
-
end
|
220
|
-
|
221
|
-
|
222
|
-
def apply_w3c_correction(x1, y1, direction)
|
223
|
-
y1 -= SCROLL_CORRECTION_W3C if direction == :down
|
224
|
-
y1 += SCROLL_CORRECTION_W3C if direction == :up
|
225
|
-
x1 -= SCROLL_CORRECTION_W3C if direction == :right
|
226
|
-
x1 += SCROLL_CORRECTION_W3C if direction == :left
|
227
|
-
[x1, y1]
|
228
|
-
end
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
def w3c_drag_to(x0, y0, x1, y1)
|
233
|
-
w3c_action(x0, y0, x1, y1, SCROLL_ACTION_TYPE_DRAG)
|
234
|
-
end
|
235
|
-
|
236
|
-
end
|
237
|
-
|
1
|
+
module TestaAppiumDriver
|
2
|
+
class ScrollActions
|
3
|
+
|
4
|
+
private
|
5
|
+
# @return [Array]
|
6
|
+
def w3c_scroll_each(direction, &block)
|
7
|
+
elements = []
|
8
|
+
begin
|
9
|
+
default_deadzone!
|
10
|
+
|
11
|
+
iterations = 0
|
12
|
+
|
13
|
+
|
14
|
+
if direction.nil?
|
15
|
+
scroll_to_start
|
16
|
+
if @scrollable.scroll_orientation == :vertical
|
17
|
+
direction = :down
|
18
|
+
else
|
19
|
+
direction = :right
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
until is_end_of_scroll?
|
24
|
+
matches = @locator.execute(skip_cache: true)
|
25
|
+
matches.each_with_index do |m|
|
26
|
+
next if elements.include?(m)
|
27
|
+
elements << m
|
28
|
+
if block_given? # block is given
|
29
|
+
block.call(m) # use call to execute the block
|
30
|
+
else # the value of block_argument becomes nil if you didn't give a block
|
31
|
+
# block was not given
|
32
|
+
end
|
33
|
+
end
|
34
|
+
iterations += 1
|
35
|
+
break if !@max_scrolls.nil? && iterations == @max_scrolls
|
36
|
+
self.send("page_#{direction}")
|
37
|
+
end
|
38
|
+
rescue => e
|
39
|
+
raise e
|
40
|
+
|
41
|
+
end
|
42
|
+
elements
|
43
|
+
end
|
44
|
+
|
45
|
+
def w3c_align(with, scroll_to_find)
|
46
|
+
default_deadzone!
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
@locator.scroll_to if scroll_to_find
|
51
|
+
|
52
|
+
element = @locator.execute
|
53
|
+
|
54
|
+
timeout = 0
|
55
|
+
until is_aligned?(with, element) || timeout == 3
|
56
|
+
w3c_attempt_align(with)
|
57
|
+
timeout += 1
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def w3c_attempt_align(with)
|
64
|
+
case with
|
65
|
+
when :top
|
66
|
+
y0 = @bounds.bottom_right.y - @deadzone[:bottom]
|
67
|
+
y1 = y0 - @align_offset
|
68
|
+
x0 = @bounds.width / 2
|
69
|
+
x1 = x0
|
70
|
+
scroll_direction = :down
|
71
|
+
when :bottom
|
72
|
+
y0 = @bounds.top_left.y + @deadzone[:top]
|
73
|
+
y1 = y0 + @align_offset
|
74
|
+
x0 = @bounds.width / 2
|
75
|
+
x1 = x0
|
76
|
+
scroll_direction = :up
|
77
|
+
when :left
|
78
|
+
x0 = @bounds.bottom_right.x - @deadzone[:right]
|
79
|
+
x1 = x0 - @align_offset
|
80
|
+
y0 = @bounds.height / 2
|
81
|
+
y1 = y0
|
82
|
+
scroll_direction = :right
|
83
|
+
when :right
|
84
|
+
x0 = @bounds.top_left.x + @deadzone[:top]
|
85
|
+
x1 = x0 + @align_offset
|
86
|
+
y0 = @bounds.height / 2
|
87
|
+
y1 = y0
|
88
|
+
scroll_direction = :left
|
89
|
+
else
|
90
|
+
raise "Unsupported align with option: #{with}"
|
91
|
+
end
|
92
|
+
|
93
|
+
x1, y1 = apply_w3c_correction(x1, y1, scroll_direction) if @driver.device == :android
|
94
|
+
w3c_action(x0, y0, x1, y1, SCROLL_ACTION_TYPE_SCROLL)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def w3c_scroll_to(direction)
|
99
|
+
|
100
|
+
rounds = 0
|
101
|
+
max_scrolls_reached = false
|
102
|
+
end_of_scroll_reached = false
|
103
|
+
until @locator.exists? || end_of_scroll_reached
|
104
|
+
end_of_scroll_reached = is_end_of_scroll?
|
105
|
+
case direction
|
106
|
+
when :down
|
107
|
+
page_down
|
108
|
+
when :right
|
109
|
+
page_right
|
110
|
+
when :left
|
111
|
+
page_left
|
112
|
+
when :up
|
113
|
+
page_up
|
114
|
+
else
|
115
|
+
scroll_to_start
|
116
|
+
@previous_elements = nil
|
117
|
+
if @scrollable.scroll_orientation == :vertical
|
118
|
+
direction = :down
|
119
|
+
else
|
120
|
+
direction = :right
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
rounds += 1
|
125
|
+
|
126
|
+
max_scrolls_reached = true if rounds == @max_scrolls
|
127
|
+
break if rounds == @max_scrolls
|
128
|
+
end
|
129
|
+
raise Selenium::WebDriver::Error::NoSuchElementError if max_scrolls_reached || end_of_scroll_reached
|
130
|
+
end
|
131
|
+
|
132
|
+
def w3c_scroll_to_start_or_end(type)
|
133
|
+
default_deadzone!
|
134
|
+
|
135
|
+
@previous_elements = nil
|
136
|
+
|
137
|
+
|
138
|
+
if type == :start
|
139
|
+
if @scrollable.scroll_orientation == :vertical
|
140
|
+
method = "fling_up"
|
141
|
+
else
|
142
|
+
method = "fling_left"
|
143
|
+
end
|
144
|
+
else
|
145
|
+
if @scrollable.scroll_orientation == :vertical
|
146
|
+
method = "fling_down"
|
147
|
+
else
|
148
|
+
method = "fling_right"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
iterations = 0
|
153
|
+
until is_end_of_scroll? || iterations >= 3
|
154
|
+
self.send(method)
|
155
|
+
iterations += 1
|
156
|
+
end
|
157
|
+
|
158
|
+
# reset the flag for end of scroll elements
|
159
|
+
@previous_elements = nil
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
def w3c_page_or_fling(type, direction)
|
164
|
+
default_deadzone!
|
165
|
+
|
166
|
+
if direction == :down || direction == :up
|
167
|
+
if direction == :down
|
168
|
+
y0 = @bounds.bottom_right.y - @deadzone[:bottom].to_i
|
169
|
+
y1 = @bounds.top_left.y + @deadzone[:top].to_i
|
170
|
+
else
|
171
|
+
y0 = @bounds.top_left.y + @deadzone[:top].to_i
|
172
|
+
y1 = @bounds.bottom_right.y - @deadzone[:bottom].to_i
|
173
|
+
end
|
174
|
+
x0 = @bounds.width / 2
|
175
|
+
x1 = x0
|
176
|
+
else
|
177
|
+
if direction == :right
|
178
|
+
x0 = @bounds.bottom_right.x - @deadzone[:right].to_i
|
179
|
+
x1 = @bounds.top_left.x + @deadzone[:left].to_i
|
180
|
+
else
|
181
|
+
x0 = @bounds.top_left.x + @deadzone[:left].to_i
|
182
|
+
x1 = @bounds.bottom_right.x - @deadzone[:right].to_i
|
183
|
+
end
|
184
|
+
y0 = @bounds.height / 2
|
185
|
+
y1 = y0
|
186
|
+
end
|
187
|
+
x1, y1 = apply_w3c_correction(x1, y1, direction) if @driver.device == :android
|
188
|
+
|
189
|
+
|
190
|
+
w3c_action(x0, y0, x1, y1, type)
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
def w3c_action(x0, y0, x1, y1, type)
|
196
|
+
if type == SCROLL_ACTION_TYPE_SCROLL
|
197
|
+
duration = 1.8
|
198
|
+
elsif type == SCROLL_ACTION_TYPE_FLING
|
199
|
+
duration = 0.1
|
200
|
+
elsif type == SCROLL_ACTION_TYPE_DRAG
|
201
|
+
duration = 3.5
|
202
|
+
else
|
203
|
+
raise "Unknown scroll action type #{type}"
|
204
|
+
end
|
205
|
+
|
206
|
+
action_builder = @driver.action
|
207
|
+
f1 = action_builder.add_pointer_input(:touch, "finger1")
|
208
|
+
f1.create_pointer_move(duration: 0, x: x0, y: y0, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
|
209
|
+
f1.create_pointer_down(:left)
|
210
|
+
|
211
|
+
f1.create_pointer_move(duration: duration, x: x1, y: y1, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
|
212
|
+
unless type == SCROLL_ACTION_TYPE_FLING
|
213
|
+
# with this move we prevent flinging/overscroll
|
214
|
+
f1.create_pointer_move(duration: 0.5, x: x1, y: y1, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
|
215
|
+
end
|
216
|
+
f1.create_pointer_up(:left)
|
217
|
+
puts "Scroll execute[w3c_action]: #{type}: {x0: #{x0}, y0: #{y0}} => {x1: #{x1}, y1: #{y1}}"
|
218
|
+
@driver.perform_actions [f1]
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
def apply_w3c_correction(x1, y1, direction)
|
223
|
+
y1 -= SCROLL_CORRECTION_W3C if direction == :down
|
224
|
+
y1 += SCROLL_CORRECTION_W3C if direction == :up
|
225
|
+
x1 -= SCROLL_CORRECTION_W3C if direction == :right
|
226
|
+
x1 += SCROLL_CORRECTION_W3C if direction == :left
|
227
|
+
[x1, y1]
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
def w3c_drag_to(x0, y0, x1, y1)
|
233
|
+
w3c_action(x0, y0, x1, y1, SCROLL_ACTION_TYPE_DRAG)
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
238
|
end
|