lib/appium_lib/android/helper.rb in appium_lib-9.4.3 vs lib/appium_lib/android/helper.rb in appium_lib-9.4.4

- old
+ new

@@ -1,11 +1,11 @@ module Appium module Android # @private # http://nokogiri.org/Nokogiri/XML/SAX.html class AndroidElements < Nokogiri::XML::SAX::Document - attr_reader :result, :keys, :instance, :filter + attr_reader :result, :keys, :filter # convert to string to support symbols def filter=(value) # nil and false disable the filter return @filter = false unless value @@ -13,26 +13,21 @@ end def initialize reset @filter = false - @instance = Hash.new(-1) end def reset @result = '' @keys = %w(text resource-id content-desc) - @instance = Hash.new(-1) end # http://nokogiri.org/Nokogiri/XML/SAX/Document.html def start_element(name, attrs = []) return if filter && !name.downcase.include?(filter) - # instance numbers start at 0. - number = instance[name] += 1 - attributes = {} attrs.each do |key, value| attributes[key] = value if keys.include?(key) && !value.empty? end @@ -76,43 +71,14 @@ string += " desc: #{desc}\n" unless desc.nil? end string += " id: #{id}\n" unless id.nil? string += " strings.xml: #{string_ids}" unless string_ids.nil? - @result += "\n#{name} (#{number})\n#{string}" unless attributes.empty? + @result += "\n#{name}\n#{string}" unless attributes.empty? end end # class AndroidElements - # Fix uiautomator's xml dump. - # https://github.com/appium/appium/issues/2822 - # https://code.google.com/p/android/issues/detail?id=74143 - def _fix_android_native_source(source) - # <android.app.ActionBar$Tab - # <android.app.ActionBar $ Tab - - # find each closing tag that contains a dollar sign. - source.scan(/<\/([^>]*\$[^>]*)>/).flatten.uniq.each do |problem_tag| - # "android.app.ActionBar$Tab" - before, after = problem_tag.split('$') - before.strip! - after.strip! - - fixed = "#{before}.#{after}" - - # now escape . in before/after because they're used in regex - before.gsub!('.', '\.') - after.gsub!('.', '\.') - - # <android.app.ActionBar$Tab => <android.app.ActionBar.Tab - # </android.app.ActionBar$Tab> => </android.app.ActionBar.Tab> - source = source.gsub(/<#{before}\s*\$\s*#{after}/, - "<#{fixed}").gsub(/<\/#{before}\s*\$\s*#{after}>/, "</#{fixed}>") - end - - source - end - # Prints xml of the current page # @return [void] def source _print_source get_source end @@ -398,16 +364,12 @@ # @return [Element] def complex_finds_exact(class_name, value) find_elements :uiautomator, string_visible_exact(class_name, value) end - # Returns XML string for the current page - # Fixes uiautomator's $ in node names. - # `android.app.ActionBar$Tab` becomes `android.app.ActionBar.Tab` + # Returns XML string for the current page via `page_source` # @return [String] def get_source - src = @driver.page_source - src = _fix_android_native_source src unless src && src.start_with?('<html>') - src + @driver.page_source end end # module Android end # module Appium