diff --git a/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt b/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt index 94ee73b..0470d27 100644 --- a/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt +++ b/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt @@ -958,6 +958,12 @@ internal fun findBoundsInTree( } == true + "idPrefix" -> attrs["resource-id"]?.let { id -> + val local = id.indexOf(":id/") + id.startsWith(value) || + (local >= 0 && id.substring(local + 4).startsWith(value)) + } == true + "text" -> attrs["text"] == value "desc" -> attrs["content-desc"] == value diff --git a/sidecar/src/test/kotlin/dev/sanderling/sidecar/DeviceOutputParserTest.kt b/sidecar/src/test/kotlin/dev/sanderling/sidecar/DeviceOutputParserTest.kt index afbccbd..38422a7 100644 --- a/sidecar/src/test/kotlin/dev/sanderling/sidecar/DeviceOutputParserTest.kt +++ b/sidecar/src/test/kotlin/dev/sanderling/sidecar/DeviceOutputParserTest.kt @@ -111,6 +111,25 @@ class DeviceOutputParserTest { assertEquals(listOf(5, 6, 7, 8), findBoundsBySelector(tree, "descPrefix:AccountCard")?.toList()) } + @Test fun findBoundsBySelectorMatchesIdPrefixWithoutThePackage() { + val tree = node( + "resource-id" to "root", + children = listOf( + node( + "resource-id" to "com.example:id/customer_row_abc", + "bounds" to "[1,2,3,4]", + ), + node("resource-id" to "supplier_row_x", "bounds" to "[5,6,7,8]"), + ), + ) + val prefix = findBoundsBySelector(tree, "idPrefix:customer_row_") + assertEquals(listOf(1, 2, 3, 4), prefix?.toList()) + val qualified = + findBoundsBySelector(tree, "idPrefix:com.example:id/customer_row") + assertEquals(listOf(1, 2, 3, 4), qualified?.toList()) + assertNull(findBoundsBySelector(tree, "idPrefix:invoice_row_")) + } + @Test fun findBoundsBySelectorReturnsNullForBadSelectorOrNoMatch() { val tree = node("resource-id" to "com.example:id/x", "bounds" to "[0,0,1,1]") assertNull(findBoundsBySelector(tree, "id"))