Skip to content

Commit 2864eec

Browse files
authored
add tests and tweak helpers which handle xml (#813)
* tweak helper * add missing puts
1 parent e04afe9 commit 2864eec

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

android_tests/lib/android/specs/android/helper.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
# larger screens have more elements
1111

1212
act = get_page_class
13-
act.must_include 'android.widget.TextView'
14-
act.must_include 'android.widget.ListView'
15-
act.must_include 'android.widget.FrameLayout'
16-
act.must_include 'hierarchy'
13+
act.split("\n").length.must_be :>=, 5
14+
act.must_include '13x android.widget.TextView'
15+
act.must_include '3x android.widget.FrameLayout'
16+
act.must_include '2x android.view.ViewGroup'
17+
act.must_include '1x android.widget.ListView'
18+
act.must_include '1x hierarchy'
1719
end
1820

1921
# t 'page_class' do # tested by get_page_class

ios_tests/lib/ios/specs/common/helper.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,16 @@ def uibutton_text
209209
end
210210

211211
t 'get_page_class' do
212-
# 8 local. 9 on sauce.
213-
get_page_class.split("\n").length.must_be :>=, 8
212+
act = get_page_class
213+
act.split("\n").length.must_be :>=, 8
214+
act.must_include '24x XCUIElementTypeStaticText'
215+
act.must_include '12x XCUIElementTypeCell'
216+
act.must_include '8x XCUIElementTypeOther'
217+
act.must_include '2x XCUIElementTypeWindow'
218+
act.must_include '1x XCUIElementTypeStatusBar'
219+
act.must_include '1x XCUIElementTypeTable'
220+
act.must_include '1x XCUIElementTypeNavigationBar'
221+
act.must_include '1x XCUIElementTypeApplication'
214222
end
215223

216224
# TODO: write tests

lib/appium_lib/common/helper.rb

+16-11
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,33 @@ def xpaths(xpath_str)
5959
class CountElements < Nokogiri::XML::SAX::Document
6060
attr_reader :result
6161

62-
def initialize
62+
def initialize(platform)
6363
reset
64+
@platform = platform
6465
end
6566

6667
def reset
6768
@result = Hash.new 0
6869
end
6970

7071
# http://nokogiri.org/Nokogiri/XML/SAX/Document.html
71-
def start_element(name, attrs = [], driver = $driver)
72-
# Count only visible elements. Android is always visible
73-
element_visible = driver.device_is_android? ? true : Hash[attrs]['visible'] == 'true'
72+
def start_element(name, attrs = [])
73+
element_visible = case @platform.to_sym
74+
when :android
75+
true
76+
else # :ios, :windows
77+
Hash[attrs]['visible'] == 'true'
78+
end
79+
7480
@result[name] += 1 if element_visible
7581
end
7682

7783
def formatted_result
78-
message = ''
79-
sorted = @result.sort_by { |_element, count| count }.reverse
80-
sorted.each do |element, count|
81-
message += "#{count}x #{element}\n"
82-
end
83-
message.strip
84+
@result
85+
.sort_by { |_element, count| count }
86+
.reverse
87+
.each_with_object('') { |element, acc| acc << "#{element[1]}x #{element[0]}\n" }
88+
.strip
8489
end
8590
end # class CountElements
8691

@@ -94,7 +99,7 @@ def formatted_result
9499
# # x XCUIElementTypeNavigationBar\n1x XCUIElementTypeApplication"
95100
#
96101
def get_page_class
97-
parser = @count_elements_parser ||= Nokogiri::XML::SAX::Parser.new(CountElements.new)
102+
parser = @count_elements_parser ||= Nokogiri::XML::SAX::Parser.new(CountElements.new(@core.device))
98103

99104
parser.document.reset
100105
parser.parse get_source

lib/appium_lib/ios/common/helper.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def page(opts = {})
6767
parser.document.reset
6868
parser.document.filter = class_name
6969
parser.parse s
70-
parser.document.result
70+
result = parser.document.result
71+
puts result
72+
result
7173
else
7274
s = get_source
7375
parser = Nokogiri::XML::SAX::Parser.new(UITestElementsPrinter.new)

0 commit comments

Comments
 (0)