Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/appium_lib/android/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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"
Expand All @@ -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?
Expand All @@ -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]
Expand Down
23 changes: 23 additions & 0 deletions test/regression_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading