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

rubocop:disable Lint/MissingSuper



77
78
79
80
# File 'lib/appium_lib/common/helper.rb', line 77

def initialize(platform) # rubocop:disable Lint/MissingSuper
  reset
  @platform = platform
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



75
76
77
# File 'lib/appium_lib/common/helper.rb', line 75

def result
  @result
end

Instance Method Details

#formatted_resultObject



98
99
100
101
102
103
104
# File 'lib/appium_lib/common/helper.rb', line 98

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

#resetObject



82
83
84
# File 'lib/appium_lib/common/helper.rb', line 82

def reset
  @result = Hash.new 0
end

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



87
88
89
90
91
92
93
94
95
96
# File 'lib/appium_lib/common/helper.rb', line 87

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