Skip to content

Commit 43ea919

Browse files
authored
[WIP]add scrollable index param into scroll_uiselector (#507)
add scrollable index param into scroll_uiselector
1 parent 80f8071 commit 43ea919

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

android_tests/lib/android/specs/android/element/generic.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,25 @@ def partial
3333
# scroll_to is broken
3434
t 'scroll_to' do
3535
wait { find('Views').click }
36-
wait { scroll_to('rotating button').text.must_equal 'Rotating Button' }
36+
wait { scroll_to('scrollbars').text.must_equal 'ScrollBars' }
37+
38+
wait { find('ScrollBars').click }
39+
wait { text('style').click }
40+
wait { scroll_to('Developers', 1).text.must_include 'What would it take to build a better mobile phone?' }
41+
back
42+
back
3743
# back to start activity
3844
back
3945
end
4046

4147
t 'scroll_to_exact' do
4248
wait { find('Views').click }
43-
wait { scroll_to_exact('Rotating Button').text.must_equal 'Rotating Button' }
49+
50+
wait { scroll_to_exact('ScrollBars').text.must_equal 'ScrollBars' }
51+
wait { find('ScrollBars').click }
52+
wait { text('style').click }
53+
back
54+
back
4455
# back to start activity
4556
back
4657
end

lib/appium_lib/android/element/generic.rb

+14-10
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,34 @@ def finds_exact(value)
2929
end
3030

3131
# @private
32-
def scroll_uiselector(content)
33-
"new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(#{content}.instance(0));"
32+
def scroll_uiselector(content, index = 0)
33+
"new UiScrollable(new UiSelector().scrollable(true).instance(#{index})).scrollIntoView(#{content}.instance(0));"
3434
end
3535

3636
# Scroll to the first element containing target text or description.
37-
# @param text [String] the text to search for in the text value and content description
37+
# @param text [String] the text or resourceId to search for in the text value and content description
38+
# @param scrollable_index [Integer] the index for scrollable views.
3839
# @return [Element] the element scrolled to
39-
def scroll_to(text)
40+
def scroll_to(text, scrollable_index = 0)
4041
text = %("#{text}")
4142

42-
args = scroll_uiselector("new UiSelector().textContains(#{text})") +
43-
scroll_uiselector("new UiSelector().descriptionContains(#{text})")
43+
args = scroll_uiselector("new UiSelector().textContains(#{text})", scrollable_index) +
44+
scroll_uiselector("new UiSelector().descriptionContains(#{text})", scrollable_index) +
45+
scroll_uiselector(resource_id(text, "new UiSelector().resourceId(#{text});"), scrollable_index)
4446

4547
find_element :uiautomator, args
4648
end
4749

4850
# Scroll to the first element with the exact target text or description.
49-
# @param text [String] the text to search for in the text value and content description
51+
# @param text [String] the text or resourceId to search for in the text value and content description
52+
# @param scrollable_index [Integer] the index for scrollable views.
5053
# @return [Element] the element scrolled to
51-
def scroll_to_exact(text)
54+
def scroll_to_exact(text, scrollable_index = 0)
5255
text = %("#{text}")
5356

54-
args = scroll_uiselector("new UiSelector().text(#{text})") +
55-
scroll_uiselector("new UiSelector().description(#{text})")
57+
args = scroll_uiselector("new UiSelector().text(#{text})", scrollable_index) +
58+
scroll_uiselector("new UiSelector().description(#{text})", scrollable_index) +
59+
scroll_uiselector(resource_id(text, "new UiSelector().resourceId(#{text});"), scrollable_index)
5660

5761
find_element :uiautomator, args
5862
end

lib/appium_lib/android/helper.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def tags(class_name)
256256
# @param on_match [String] the string to return on resourceId match
257257
#
258258
# @return [String] empty string on failure, on_match on successful match
259-
def _resource_id(string, on_match)
259+
def resource_id(string, on_match)
260260
return '' unless string
261261

262262
# unquote the string
@@ -289,14 +289,14 @@ def string_visible_contains(class_name, value)
289289
value = %("#{value}")
290290

291291
if class_name == '*'
292-
return (_resource_id(value, "new UiSelector().resourceId(#{value});") +
292+
return (resource_id(value, "new UiSelector().resourceId(#{value});") +
293293
"new UiSelector().descriptionContains(#{value});" \
294294
"new UiSelector().textContains(#{value});")
295295
end
296296

297297
class_name = %("#{class_name}")
298298

299-
_resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
299+
resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
300300
"new UiSelector().className(#{class_name}).descriptionContains(#{value});" \
301301
"new UiSelector().className(#{class_name}).textContains(#{value});"
302302
end
@@ -326,14 +326,14 @@ def string_visible_exact(class_name, value)
326326
value = %("#{value}")
327327

328328
if class_name == '*'
329-
return (_resource_id(value, "new UiSelector().resourceId(#{value});") +
329+
return (resource_id(value, "new UiSelector().resourceId(#{value});") +
330330
"new UiSelector().description(#{value});" \
331331
"new UiSelector().text(#{value});")
332332
end
333333

334334
class_name = %("#{class_name}")
335335

336-
_resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
336+
resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
337337
"new UiSelector().className(#{class_name}).description(#{value});" \
338338
"new UiSelector().className(#{class_name}).text(#{value});"
339339
end

0 commit comments

Comments
 (0)