Class: Appium::Android::AndroidElements
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Appium::Android::AndroidElements
- Defined in:
- lib/appium_lib/android/helper.rb
Overview
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize ⇒ AndroidElements
constructor
A new instance of AndroidElements.
- #reset ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize ⇒ AndroidElements
Returns a new instance of AndroidElements.
15 16 17 18 19 |
# File 'lib/appium_lib/android/helper.rb', line 15 def initialize reset @filter = false @instance = Hash.new(-1) end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
6 7 8 |
# File 'lib/appium_lib/android/helper.rb', line 6 def filter @filter end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
6 7 8 |
# File 'lib/appium_lib/android/helper.rb', line 6 def instance @instance end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
6 7 8 |
# File 'lib/appium_lib/android/helper.rb', line 6 def keys @keys end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/appium_lib/android/helper.rb', line 6 def result @result end |
Instance Method Details
#reset ⇒ Object
21 22 23 24 25 |
# File 'lib/appium_lib/android/helper.rb', line 21 def reset @result = '' @keys = %w(text resource-id content-desc) @instance = Hash.new(-1) end |
#start_element(name, attrs = []) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/appium_lib/android/helper.rb', line 28 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 # scoped to: text resource-id content-desc attributes_values = attributes.values strings = $driver.lazy_load_strings id_matches = [] unless strings.empty? id_matches = strings.select do |_key, value| attributes_values.include? value end end string_ids = nil if id_matches && !id_matches.empty? space_suffix = ' ' * 15 # 15 is ' strings.xml: '.length string_ids = '' # add first string_ids += "#{id_matches.shift[0]}\n" # use padding for remaining values # [0] = key, [1] = value id_matches.each do |match| string_ids += "#{space_suffix}#{match[0]}\n" end end string = '' text = attributes['text'] desc = attributes['content-desc'] id = attributes['resource-id'] if !text.nil? && text == desc string += " text, desc: #{text}\n" else string += " text: #{text}\n" unless text.nil? 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? end |