lib/appium_lib/android/element/button.rb in appium_lib-9.5.0 vs lib/appium_lib/android/element/button.rb in appium_lib-9.6.0
- old
+ new
@@ -1,40 +1,10 @@
-# UIAButton methods
module Appium
module Android
Button = 'android.widget.Button'.freeze
ImageButton = 'android.widget.ImageButton'.freeze
- private
-
- def _button_visible_selectors(opts = {})
- button_index = opts.fetch :button_index, false
- image_button_index = opts.fetch :image_button_index, false
-
- if button_index && image_button_index
- "new UiSelector().className(#{Button}).instance(#{button_index});" \
- "new UiSelector().className(#{ImageButton}).instance(#{image_button_index});"
- else
- "new UiSelector().className(#{Button});" \
- "new UiSelector().className(#{ImageButton});"
- end
- end
-
- def _button_exact_string(value)
- button = string_visible_exact Button, value
- image_button = string_visible_exact ImageButton, value
- button + image_button
- end
-
- def _button_contains_string(value)
- button = string_visible_contains Button, value
- image_button = string_visible_contains ImageButton, value
- button + image_button
- end
-
- public
-
# Find the first button that contains value or by index.
# @param value [String, Integer] the value to exactly match.
# If int then the button at that index is returned.
# @return [Button]
def button(value)
@@ -42,25 +12,14 @@
# Android needs to combine button and image button to match iOS.
if value.is_a? Numeric
index = value
raise "#{index} is not a valid index. Must be >= 1" if index <= 0
- unless automation_name_is_uiautomator2?
- return find_element :uiautomator, _button_visible_selectors(index: index)
- end
-
- result = find_elements :uiautomator, _button_visible_selectors(index: index)
- raise _no_such_element if result.empty?
- return result[value - 1]
+ return find_element :uiautomator, _button_visible_selectors(index: index)
end
- if automation_name_is_uiautomator2?
- elements = find_elements :uiautomator, _button_contains_string(value)
- raise_no_such_element_if_empty(elements)
- else
- find_element :uiautomator, _button_contains_string(value)
- end
+ find_element :uiautomator, _button_contains_string(value)
end
# Find all buttons containing value.
# If value is omitted, all buttons are returned.
# @param value [String] the value to search for
@@ -71,16 +30,11 @@
end
# Find the first button.
# @return [Button]
def first_button
- if automation_name_is_uiautomator2?
- elements = find_elements :uiautomator, _button_visible_selectors(button_index: 0, image_button_index: 0)
- raise_no_such_element_if_empty(elements)
- else
- find_element :uiautomator, _button_visible_selectors(button_index: 0, image_button_index: 0)
- end
+ find_element :uiautomator, _button_visible_selectors(button_index: 0, image_button_index: 0)
end
# Find the last button.
# @return [Button]
def last_button
@@ -89,32 +43,20 @@
button_index = tags(Button).length
button_index -= 1 if button_index > 0
image_button_index = tags(ImageButton).length
image_button_index -= 1 if image_button_index > 0
- if automation_name_is_uiautomator2?
- elements = find_elements :uiautomator,
- _button_visible_selectors(button_index: button_index,
- image_button_index: image_button_index)
- raise_no_such_element_if_empty(elements)
- else
- find_element :uiautomator,
- _button_visible_selectors(button_index: button_index,
- image_button_index: image_button_index)
- end
+ find_element :uiautomator,
+ _button_visible_selectors(button_index: button_index,
+ image_button_index: image_button_index)
end
# Find the first button that exactly matches value.
# @param value [String] the value to match exactly
# @return [Button]
def button_exact(value)
- if automation_name_is_uiautomator2?
- elements = find_elements :uiautomator, _button_exact_string(value)
- raise_no_such_element_if_empty(elements)
- else
- find_element :uiautomator, _button_exact_string(value)
- end
+ find_element :uiautomator, _button_exact_string(value)
end
# Find all buttons that exactly match value.
# @param value [String] the value to match exactly
# @return [Array<Button>]
@@ -122,11 +64,40 @@
find_elements :uiautomator, _button_exact_string(value)
end
private
+ # @private
def raise_no_such_element_if_empty(elements)
raise _no_such_element if elements.empty?
elements.first
+ end
+
+ # @private
+ def _button_visible_selectors(opts = {})
+ button_index = opts.fetch :button_index, false
+ image_button_index = opts.fetch :image_button_index, false
+
+ if button_index && image_button_index
+ "new UiSelector().className(#{Button}).instance(#{button_index});" \
+ "new UiSelector().className(#{ImageButton}).instance(#{image_button_index});"
+ else
+ "new UiSelector().className(#{Button});" \
+ "new UiSelector().className(#{ImageButton});"
+ end
+ end
+
+ # @private
+ def _button_exact_string(value)
+ button = string_visible_exact Button, value
+ image_button = string_visible_exact ImageButton, value
+ button + image_button
+ end
+
+ # @private
+ def _button_contains_string(value)
+ button = string_visible_contains Button, value
+ image_button = string_visible_contains ImageButton, value
+ button + image_button
end
end # module Android
end # module Appium