From e1767e4606712dfa42f1b65ed6de6bff04d79701 Mon Sep 17 00:00:00 2001 From: Nacy Dev <140143646+hoanle0126@users.noreply.github.com> Date: Mon, 26 Oct 2026 09:24:14 +0700 Subject: [PATCH] feat: include view-tag attribute in Android page inspection --- lib/appium_lib/android/common/helper.rb | 8 +++++--- test/regression_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/appium_lib/android/common/helper.rb b/lib/appium_lib/android/common/helper.rb index b0245f08..50cb291b 100644 --- a/lib/appium_lib/android/common/helper.rb +++ b/lib/appium_lib/android/common/helper.rb @@ -34,7 +34,7 @@ def initialize # rubocop:disable Lint/MissingSuper def reset @result = '' - @keys = %w(text resource-id content-desc) + @keys = %w(text resource-id content-desc view-tag) end # http://nokogiri.org/Nokogiri/XML/SAX/Document.html @@ -47,7 +47,7 @@ def start_element(name, attrs = [], driver = $driver) attributes[key] = value if keys.include?(key) && !value.empty? end - # scoped to: text resource-id content-desc + # scoped to: text resource-id content-desc view-tag attributes_values = attributes.values strings = driver.lazy_load_strings id_matches = strings.empty? ? [] : strings.select { |_key, value| attributes_values.include? value } @@ -72,6 +72,7 @@ def start_element(name, attrs = [], driver = $driver) text = attributes['text'] desc = attributes['content-desc'] id = attributes['resource-id'] + tag = attributes['view-tag'] if !text.nil? && text == desc string += " text, desc: #{text}\n" @@ -80,6 +81,7 @@ def start_element(name, attrs = [], driver = $driver) string += " desc: #{desc}\n" unless desc.nil? end string += " id: #{id}\n" unless id.nil? + string += " tag: #{tag}\n" unless tag.nil? string += " strings.xml: #{string_ids}" unless string_ids.nil? @result += "\n#{name}\n#{string}" unless attributes.empty? @@ -88,7 +90,7 @@ def start_element(name, attrs = [], driver = $driver) # Android only. # Returns a string containing interesting elements. - # The text, content description, and id are returned. + # The text, content description, id, and view tag are returned. # @param class_name [String] the class name to filter on. # if false (default) then all classes will be inspected # @return [String] diff --git a/test/regression_test.rb b/test/regression_test.rb index cccf6750..c91dc06a 100644 --- a/test/regression_test.rb +++ b/test/regression_test.rb @@ -119,6 +119,29 @@ def test_start_driver_builds_default_http_client assert_instance_of Appium::Http::Default, driver.http_client end + def test_android_elements_includes_view_tag + stub_driver = Object.new + def stub_driver.lazy_load_strings + {} + end + + doc = Appium::Android::AndroidElements.new + doc.start_element( + 'android.widget.Button', + [['text', 'Submit'], ['resource-id', 'com.example:id/submit'], ['view-tag', 'submit_btn']], + stub_driver + ) + doc.start_element( + 'androidx.compose.ui.platform.ComposeView', + [['view-tag', 'compose_tag']], + stub_driver + ) + + expected = "\nandroid.widget.Button\n text: Submit\n id: com.example:id/submit\n tag: submit_btn\n" \ + "\nandroidx.compose.ui.platform.ComposeView\n tag: compose_tag\n" + assert_equal expected, doc.result + end + private def build_driver