Class: Appium::Common::HTMLElements

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/appium_lib/common/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTMLElements

Returns a new instance of HTMLElements.



202
203
204
205
# File 'lib/appium_lib/common/helper.rb', line 202

def initialize
  reset
  @filter = false
end

Instance Attribute Details

#filterObject

Returns the value of attribute filter.



192
193
194
# File 'lib/appium_lib/common/helper.rb', line 192

def filter
  @filter
end

Instance Method Details

#characters(chars) ⇒ Object



243
244
245
246
247
248
# File 'lib/appium_lib/common/helper.rb', line 243

def characters(chars)
  return if @skip_element

  element        = @element_stack.last
  element[:text] = chars
end

#end_element(name) ⇒ Object



236
237
238
239
240
241
# File 'lib/appium_lib/common/helper.rb', line 236

def end_element(name)
  return if filter && !filter.include?(name.downcase)

  element_index = @element_stack.rindex { |e| e[:name] == name }
  @element_stack.delete_at element_index
end

#resetObject



207
208
209
210
211
# File 'lib/appium_lib/common/helper.rb', line 207

def reset
  @element_stack     = []
  @elements_in_order = []
  @skip_element      = false
end

#resultObject



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/appium_lib/common/helper.rb', line 213

def result
  @elements_in_order.reduce('') do |r, e|
    name = e.delete :name
    attr_string = e.reduce('') do |string, attr|
      attr1 = attr[1] ? attr[1].strip : attr[1]
      "#{string}  #{attr[0]}: #{attr1}\n"
    end

    r.concat "\n#{name}\n#{attr_string}" unless attr_string.nil? || attr_string.empty?
    r
  end
end

#start_element(name, attrs = []) ⇒ Object



226
227
228
229
230
231
232
233
234
# File 'lib/appium_lib/common/helper.rb', line 226

def start_element(name, attrs = [])
  @skip_element = filter && !filter.include?(name.downcase)
  return if @skip_element

  element = { name: name }
  attrs.each { |a| element[a[0]] = a[1] }
  @element_stack.push element
  @elements_in_order.push element
end