10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/aaet/android/parser.rb', line 10
def start_element(name, attrs = [], driver = driver)
return if filter && !name.downcase.include?(filter)
attributes = {}
do_not_include = ["android:id/content", "android:id/navigationBarBackground", "android:id/content",
"android:id/parentPanel", "android:id/topPanel", "android:id/title_template",
"android:id/contentPanel", "android:id/scrollView", "android:id/buttonPanel"]
attrs.each do |key, value|
next if do_not_include.include? value
if key.include? "-"
key = key.gsub("-","_")
end
if key == "resource_id"
key = "id"
elsif key == "content_desc"
key = "accessibilty_label"
end
if ["android:id/button2", "android:id/button1"].include? value
attributes["dialog"] = true
end
if value.empty?
value = nil
end
if key == "bounds"
bounds_array = value.scan(/\d*/).reject { |c| c.empty? }.map { |v| v = v.to_i }
bounds_array_value = bounds_array.each_slice((bounds_array.size/2.0).round).to_a
attributes["bounds_array"] = bounds_array_value
end
attributes[key] = value
end
eval_attrs = ["checkable", "checked", "clickable", "enabled", "focusable", "focused",
"scrollable", "long_clickable", "password", "selected", "instance", "index"]
@result << attributes.reduce({}) do |memo, (k, v)|
if eval_attrs.include? k.to_s
v = eval(v) rescue false
end
memo.merge({ k.to_sym => v})
end
end
|