Class: Appium::Common::CountElements
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Appium::Common::CountElements
- Defined in:
- lib/appium_lib/common/helper.rb
Overview
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #formatted_result ⇒ Object
-
#initialize ⇒ CountElements
constructor
A new instance of CountElements.
- #reset ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize ⇒ CountElements
Returns a new instance of CountElements.
71 72 73 |
# File 'lib/appium_lib/common/helper.rb', line 71 def initialize reset end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
69 70 71 |
# File 'lib/appium_lib/common/helper.rb', line 69 def result @result end |
Instance Method Details
#formatted_result ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/appium_lib/common/helper.rb', line 86 def formatted_result = '' sorted = @result.sort_by { |_element, count| count }.reverse sorted.each do |element, count| += "#{count}x #{element}\n" end .strip end |
#reset ⇒ Object
75 76 77 |
# File 'lib/appium_lib/common/helper.rb', line 75 def reset @result = Hash.new 0 end |
#start_element(name, attrs = []) ⇒ Object
80 81 82 83 84 |
# File 'lib/appium_lib/common/helper.rb', line 80 def start_element(name, attrs = []) # Count only visible elements. Android is always visible element_visible = $driver.device_is_android? ? true : Hash[attrs]['visible'] == 'true' @result[name] += 1 if element_visible end |