lib/appium_lib/android/espresso/element/button.rb in appium_lib-10.2.0 vs lib/appium_lib/android/espresso/element/button.rb in appium_lib-10.3.0

- old
+ new

@@ -1,5 +1,19 @@ +# frozen_string_literal: true + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + module Appium module Android module Espresso module Element # Find the first button that contains value or by index. @@ -15,12 +29,12 @@ # zero index _button_visible_selectors_xpath(index: index - 1) end - i = find_elements :xpath, _button_contains_string_xpath(Button, value) - e = find_elements :xpath, _button_contains_string_xpath(ImageButton, value) + i = find_elements :xpath, _button_contains_string_xpath(BUTTON, value) + e = find_elements :xpath, _button_contains_string_xpath(IMAGE_BUTTON, value) raise_no_such_element_if_empty(i + e) (i + e)[0] end @@ -30,12 +44,12 @@ # @param value [String] the value to search for # @return [Array<Button>] def buttons(value = false) return _button_visible_selectors_xpath unless value - i = find_elements :xpath, _button_contains_string_xpath(Button, value) - e = find_elements :xpath, _button_contains_string_xpath(ImageButton, value) + i = find_elements :xpath, _button_contains_string_xpath(BUTTON, value) + e = find_elements :xpath, _button_contains_string_xpath(IMAGE_BUTTON, value) i + e end # Find the first button. # @return [Button] @@ -46,37 +60,37 @@ # Find the last button. # @return [Button] def last_button # uiautomator index doesn't support last # and it's 0 indexed - button_index = tags(::Appium::Android::Button).length + button_index = tags(::Appium::Android::BUTTON).length button_index -= 1 if button_index > 0 - image_button_index = tags(::Appium::Android::ImageButton).length + image_button_index = tags(::Appium::Android::IMAGE_BUTTON).length image_button_index -= 1 if image_button_index > 0 _button_visible_selectors_xpath(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) - i = find_elements :xpath, _button_exact_string_xpath(Button, value) - e = find_elements :xpath, _button_exact_string_xpath(ImageButton, value) + i = find_elements :xpath, _button_exact_string_xpath(BUTTON, value) + e = find_elements :xpath, _button_exact_string_xpath(IMAGE_BUTTON, value) raise_no_such_element_if_empty(i + e) (i + e)[0] end # Find all buttons that exactly match value. # @param value [String] the value to match exactly # @return [Array<Button>] def buttons_exact(value) - i = find_elements :xpath, _button_exact_string_xpath(Button, value) - e = find_elements :xpath, _button_exact_string_xpath(ImageButton, value) + i = find_elements :xpath, _button_exact_string_xpath(BUTTON, value) + e = find_elements :xpath, _button_exact_string_xpath(IMAGE_BUTTON, value) i + e end private @@ -91,11 +105,11 @@ button_index = opts.fetch :button_index, false image_button_index = opts.fetch :image_button_index, false index = opts.fetch :index, false - b = find_elements :xpath, "//#{Button}" - i = find_elements :xpath, "//#{ImageButton}" + b = find_elements :xpath, "//#{BUTTON}" + i = find_elements :xpath, "//#{IMAGE_BUTTON}" if index raise_no_such_element_if_empty(b + i) (b + i)[index] elsif button_index && image_button_index