diff --git a/CHANGELOG.md b/CHANGELOG.md index cf398365..bc1abb1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ Release tags are https://github.com/appium/ruby_lib/releases . ### 1. Enhancements - add `mobile: installCertificate` shortcut for XCUITest - add `mobile: getContexts` shortcut for XCUITest +- Add `find_element_by_image` and `find_elements_by_image` to handle `ImageElement` + - Read a [PR](https://github.com/appium/ruby_lib/pull/795/files) and [Core](https://github.com/appium/ruby_lib_core/blob/master/CHANGELOG.md#enhancements-1) for more details + - Experimental feature ### 2. Bug fixes diff --git a/appium_lib.gemspec b/appium_lib.gemspec index 8cb0591f..4f1ccb06 100644 --- a/appium_lib.gemspec +++ b/appium_lib.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/appium/ruby_lib' # published as appium_lib s.require_paths = ['lib'] - s.add_runtime_dependency 'appium_lib_core', '~> 1.7.0' + s.add_runtime_dependency 'appium_lib_core', '~> 1.7.2' s.add_runtime_dependency 'tomlrb', '~> 1.1' s.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.1' diff --git a/lib/appium_lib/driver.rb b/lib/appium_lib/driver.rb index 4796dca9..d970c94a 100644 --- a/lib/appium_lib/driver.rb +++ b/lib/appium_lib/driver.rb @@ -631,6 +631,43 @@ def find_element(*args) @driver.find_element(*args) end + # Return ImageElement if current view has a partial image + # + # @param [String] png_img_path A path to a partial image you'd like to find + # @param [Flood] match_threshold At what normalized threshold to reject + # @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of + # the corresponding picture matching operation. This option is disabled by default. + # + # @return [::Appium::Core::ImageElement] + # @raise [::Appium::Core::Error::NoSuchElementError|::Appium::Core::Error::CoreError] No such element + # + # @example + # + # @driver.find_element_by_image './test/functional/data/test_element_image.png' + # + DEFAULT_MATCH_THRESHOLD = 0.5 + def find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) + @driver.find_element_by_image(png_img_path, match_threshold: match_threshold, visualize: visualize) + end + + # Return ImageElement if current view has partial images + # + # @param [[String]] png_img_paths Paths to a partial image you'd like to find + # @param [Flood] match_threshold At what normalized threshold to reject + # @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of + # the corresponding picture matching operation. This option is disabled by default. + # + # @return [[::Appium::Core::ImageElement]] + # @return [::Appium::Core::Error::CoreError] + # + # @example + # + # @driver.find_elements_by_image ['./test/functional/data/test_element_image.png'] + # + def find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) + @driver.find_elements_by_image(png_img_paths, match_threshold: match_threshold, visualize: visualize) + end + # Calls @driver.set_location # # @note This method does not work on real devices.