Skip to content

Commit bb5b7a5

Browse files
Add page_class for iOS
1 parent 96688ee commit bb5b7a5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/appium_lib/ios/helper.rb

+32
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ def password length=1
5151
'•' * length
5252
end
5353

54+
# Returns a string of class counts.
55+
def get_page_class
56+
r = []
57+
run_internal = lambda do |node|
58+
if node.kind_of? Array
59+
node.each { |node| run_internal.call node }
60+
return
61+
end
62+
63+
keys = node.keys
64+
return if keys.empty?
65+
r.push node['type'] if keys.include?('type')
66+
67+
run_internal.call node['children'] if keys.include?('children')
68+
end
69+
json = get_source
70+
run_internal.call json['children']
71+
72+
res = []
73+
r = r.sort
74+
r.uniq.each do |ele|
75+
res.push "#{r.count(ele)}x #{ele}\n"
76+
end
77+
count_sort = ->(one,two) { two.match(/(\d+)x/)[1].to_i <=> one.match(/(\d+)x/)[1].to_i }
78+
res.sort(&count_sort).join ''
79+
end
80+
81+
def page_class
82+
puts get_page_class
83+
nil
84+
end
85+
5486
# Returns a string of interesting elements. iOS only.
5587
#
5688
# @param element [Object] the element to search. omit to search everything

0 commit comments

Comments
 (0)