@@ -248,6 +248,36 @@ def tags class_name
248
248
end
249
249
250
250
# @private
251
+ # Detects if the string represents a resourceId
252
+ # resourceId is only supported on API >= 18 devices
253
+ #
254
+ # @param string [String] the string check for a resourceId
255
+ # value will be auto unquoted
256
+ # @param on_match [String] the string to return on resourceId match
257
+ #
258
+ # @return [String] empty string on failure, on_match on successful match
259
+ def _resourceId string , on_match
260
+ return '' unless string
261
+
262
+ # unquote the string
263
+ # "com.example.Test:id/enter" -> com.example.Test:id/enter
264
+ unquote = string . match ( /"(.+)"/ )
265
+ string = unquote [ 1 ] if unquote
266
+
267
+ # java_package : type / name
268
+ #
269
+ # com.example.Test:id/enter
270
+ #
271
+ # ^[a-zA-Z_] - Java package must start with letter or underscore
272
+ # [a-zA-Z0-9\._]* - Java package may contain letters, numbers, periods and underscores
273
+ # : - : ends the package and starts the type
274
+ # [^\/]+ - type is made up of at least one non-/ characters
275
+ # \\/ - / ends the type and starts the name
276
+ # [\S]+$ - the name contains at least one non-space character and then the line is ended
277
+ resource_id = /^[a-zA-Z_][a-zA-Z0-9\. _]*:[^\/ ]+\/ [\S ]+$/
278
+ string . match ( resource_id ) ? on_match : ''
279
+ end
280
+
251
281
# Returns a string that matches the first element that contains value
252
282
#
253
283
# example: complex_find_contains 'UIATextField', 'sign in'
@@ -259,14 +289,14 @@ def string_visible_contains class_name, value
259
289
value = %Q("#{ value } ")
260
290
261
291
if class_name == '*'
262
- return "new UiSelector().resourceId(#{ value } );" +
292
+ return _resourceId ( value , "new UiSelector().resourceId(#{ value } );" ) +
263
293
"new UiSelector().descriptionContains(#{ value } );" +
264
294
"new UiSelector().textContains(#{ value } );"
265
295
end
266
296
267
297
class_name = %Q("#{ class_name } ")
268
298
269
- "new UiSelector().className(#{ class_name } ).resourceId(#{ value } );" +
299
+ _resourceId ( value , "new UiSelector().className(#{ class_name } ).resourceId(#{ value } );" ) +
270
300
"new UiSelector().className(#{ class_name } ).descriptionContains(#{ value } );" +
271
301
"new UiSelector().className(#{ class_name } ).textContains(#{ value } );"
272
302
end
@@ -296,14 +326,14 @@ def string_visible_exact class_name, value
296
326
value = %Q("#{ value } ")
297
327
298
328
if class_name == '*'
299
- return "new UiSelector().resourceId(#{ value } );" +
329
+ return _resourceId ( value , "new UiSelector().resourceId(#{ value } );" ) +
300
330
"new UiSelector().description(#{ value } );" +
301
331
"new UiSelector().text(#{ value } );"
302
332
end
303
333
304
334
class_name = %Q("#{ class_name } ")
305
335
306
- "new UiSelector().className(#{ class_name } ).resourceId(#{ value } );" +
336
+ _resourceId ( value , "new UiSelector().className(#{ class_name } ).resourceId(#{ value } );" ) +
307
337
"new UiSelector().className(#{ class_name } ).description(#{ value } );" +
308
338
"new UiSelector().className(#{ class_name } ).text(#{ value } );"
309
339
end
0 commit comments