Class: Appium::Common::CountElements

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform) ⇒ CountElements

Returns a new instance of CountElements.



62
63
64
65
# File 'lib/appium_lib/common/helper.rb', line 62

def initialize(platform)
  reset
  @platform = platform
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



60
61
62
# File 'lib/appium_lib/common/helper.rb', line 60

def result
  @result
end

Instance Method Details

#formatted_resultObject



83
84
85
86
87
88
89
# File 'lib/appium_lib/common/helper.rb', line 83

def formatted_result
  @result
    .sort_by { |_element, count| count }
    .reverse
    .each_with_object('') { |element, acc| acc << "#{element[1]}x #{element[0]}\n" }
    .strip
end

#resetObject



67
68
69
# File 'lib/appium_lib/common/helper.rb', line 67

def reset
  @result = Hash.new 0
end

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



72
73
74
75
76
77
78
79
80
81
# File 'lib/appium_lib/common/helper.rb', line 72

def start_element(name, attrs = [])
  element_visible = case @platform.to_sym
                    when :android
                      true
                    else # :ios, :windows
                      Hash[attrs]['visible'] == 'true'
                    end

  @result[name] += 1 if element_visible
end