@@ -39,6 +39,28 @@ def start_element name, attrs = []
39
39
end
40
40
end
41
41
42
+ # scoped to: text resource-id content-desc
43
+ attributes_values = attributes . values
44
+ id_matches = $driver. lazy_load_strings . select do |key , value |
45
+ attributes_values . include? value
46
+ end
47
+
48
+ string_ids = nil
49
+
50
+ if id_matches && id_matches . length > 0
51
+ space_suffix = ' ' * ' strings.xml: ' . length
52
+ string_ids = ''
53
+
54
+ # add first
55
+ string_ids += "#{ id_matches . shift [ 0 ] } \n "
56
+
57
+ # use padding for remaining values
58
+ # [0] = key, [1] = value
59
+ id_matches . each do |match |
60
+ string_ids += "#{ space_suffix } #{ match [ 0 ] } \n "
61
+ end
62
+ end
63
+
42
64
string = ''
43
65
text = attributes [ 'text' ]
44
66
desc = attributes [ 'content-desc' ]
@@ -51,6 +73,7 @@ def start_element name, attrs = []
51
73
string += " desc: #{ desc } \n " unless desc . nil?
52
74
end
53
75
string += " id: #{ id } \n " unless id . nil?
76
+ string += " strings.xml: #{ string_ids } " unless string_ids . nil?
54
77
55
78
@result += "\n #{ name } \n #{ string } " unless attributes . empty?
56
79
end
@@ -97,17 +120,29 @@ def current_app
97
120
am_start : pkg + '/' + act )
98
121
end
99
122
100
- # Find by id
101
- # @param id [String] the id to search for
102
- # @return [Element]
103
- def id id
104
- value = resolve_id id
123
+ # @private
124
+ def string_id_xpath id
125
+ value = resolve_id id
105
126
# If the id doesn't resolve in strings.xml then use it as is
106
127
# It's probably a resource id which won't be in strings.xml
107
- value = id unless value
128
+ value = id unless value
108
129
exact = string_visible_exact '*' , value
109
130
contains = string_visible_contains '*' , value
110
- xpath "#{ exact } | #{ contains } "
131
+ "#{ exact } | #{ contains } "
132
+ end
133
+
134
+ # Find the first matching element by id
135
+ # @param id [String] the id to search for
136
+ # @return [Element]
137
+ def id id
138
+ xpath string_id_xpath id
139
+ end
140
+
141
+ # Find all matching elements by id
142
+ # @param id [String] the id to search for
143
+ # @return [Element]
144
+ def ids id
145
+ xpaths string_id_xpath id
111
146
end
112
147
113
148
# Find the element of type class_name at matching index.
0 commit comments