Class: Appium::Android::AndroidElements
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Appium::Android::AndroidElements
- Defined in:
- lib/appium_lib/android/common/helper.rb
Overview
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#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
rubocop:disable Lint/MissingSuper.
- #reset ⇒ Object
- #start_element(name, attrs = [], driver = $driver) ⇒ Object
Constructor Details
#initialize ⇒ AndroidElements
rubocop:disable Lint/MissingSuper
30 31 32 33 |
# File 'lib/appium_lib/android/common/helper.rb', line 30 def initialize # rubocop:disable Lint/MissingSuper reset @filter = false end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
20 21 22 |
# File 'lib/appium_lib/android/common/helper.rb', line 20 def filter @filter end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
20 21 22 |
# File 'lib/appium_lib/android/common/helper.rb', line 20 def keys @keys end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
20 21 22 |
# File 'lib/appium_lib/android/common/helper.rb', line 20 def result @result end |
Instance Method Details
#reset ⇒ Object
35 36 37 38 |
# File 'lib/appium_lib/android/common/helper.rb', line 35 def reset @result = '' @keys = %w(text resource-id content-desc) end |
#start_element(name, attrs = [], driver = $driver) ⇒ Object
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 83 84 85 86 |
# File 'lib/appium_lib/android/common/helper.rb', line 41 def start_element(name, attrs = [], driver = $driver) return if filter && !name.downcase.include?(filter) 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 = strings.empty? ? [] : strings.select { |_key, value| attributes_values.include? value } 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}\n#{string}" unless attributes.empty? end |