UiSelector DSL
For Android screens, Kolibrium provides a type-safe DSL for building UIAutomator UiSelector expressions - no raw Java strings required. Use uiSelector { } with androidUIAutomator or androidUIAutomators.
val loginButton by androidUIAutomator(uiSelector { text("Login") })
val listItem by androidUIAutomator(uiSelector {
className("android.widget.TextView")
textContains("Product")
enabled()
})
Available matchers
Text
| Function | Matches when… |
|---|---|
text(value) | element text equals value exactly |
textContains(value) | element text contains value |
textStartsWith(value) | element text starts with value |
textMatches(regex) | element text matches regex pattern |
Content description
| Function | Matches when… |
|---|---|
description(value) | content description equals value exactly |
descriptionContains(value) | content description contains value |
descriptionStartsWith(value) | content description starts with value |
descriptionMatches(regex) | content description matches regex pattern |
Identity & state
| Function | Matches when… |
|---|---|
className(value) | element class name equals value |
resourceId(value) | element resource name equals value |
clickable(value = true) | element is (or isn't) clickable |
enabled(value = true) | element is (or isn't) enabled |
focusable(value = true) | element is (or isn't) focusable |
scrollable(value = true) | element is (or isn't) scrollable |
Position
| Function | Matches when… |
|---|---|
index(index) | element is at index among siblings |
instance(n) | element is the n-th match (zero-based) |
Combining clauses
All clauses in a single uiSelector { } block are chained as a single UiSelector expression:
val addToCart by androidUIAutomator(uiSelector {
className("android.widget.Button")
textContains("Add To Cart")
enabled()
instance(0)
})