Skip to content

Commit 062a2a2

Browse files
Add page_class
Example: > page_class get /source 1x android.view.View 1x android.widget.Button 2x android.widget.EditText 4x android.widget.FrameLayout 1x android.widget.ImageButton 1x android.widget.ImageView 9x android.widget.LinearLayout 1x android.widget.Spinner 7x android.widget.TextView
1 parent 9e1e091 commit 062a2a2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/appium_lib/android/helper.rb

+27
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,33 @@ def run node
129129
out
130130
end
131131

132+
# Count all classes on screen and print to stdout.
133+
# Useful for appium_console.
134+
def page_class
135+
r = []
136+
run_internal = lambda do |node|
137+
if node.kind_of? Array
138+
node.each { |node| run_internal.call node }
139+
return
140+
end
141+
142+
keys = node.keys
143+
return if keys.empty?
144+
r.push node['@class'] if keys.include?('@class')
145+
146+
run_internal.call node['node'] if keys.include?('node')
147+
end
148+
json = get_source
149+
run_internal.call json['hierarchy']
150+
151+
r = r.sort
152+
r.uniq.each do |ele|
153+
print r.count(ele)
154+
puts "x #{ele}\n"
155+
end
156+
nil
157+
end
158+
132159
# Android only.
133160
# Returns a string containing interesting elements.
134161
# If an element has no content desc or text, then it's not returned by this method.

0 commit comments

Comments
 (0)