Skip to main content

NSPredicate DSL

For iOS screens, Kolibrium provides a type-safe DSL for building NSPredicate expressions — no raw predicate strings required. Use nsPredicate { } with iOSNSPredicate or iOSNSPredicates.

val loginButton by iOSNSPredicate(nsPredicate {
label equalTo "Login"
isEnabled equalTo true
})

Multiple top-level clauses are joined with AND.

Attributes​

String​

AttributeNSPredicate key
typetype
namename
labellabel
valuevalue

Boolean​

AttributeNSPredicate key
isEnabledenabled
isVisiblevisible
accessibleaccessible
selectedselected
focusedfocused
hittablehittable

Rect (numeric)​

Access via rect.x, rect.y, rect.width, rect.height.

String matchers​

All string matchers accept an optional StringModifier (CaseInsensitive, DiacriticInsensitive, or both).

FunctionProduces
attr equalTo "value"attr == 'value'
attr notEqualTo "value"attr != 'value'
attr.contains("v", modifier?)attr CONTAINS[modifier] 'v'
attr.beginsWith("v", modifier?)attr BEGINSWITH[modifier] 'v'
attr.endsWith("v", modifier?)attr ENDSWITH[modifier] 'v'
attr.like("v*", modifier?)attr LIKE[modifier] 'v*'
attr.matches("regex", modifier?)attr MATCHES[modifier] 'regex'
attr isIn listOf("a", "b")attr IN {'a', 'b'}

Numeric matchers​

FunctionProduces
attr equalTo 42attr == 42
attr notEqualTo 42attr != 42
attr greaterThan 42attr > 42
attr greaterThanOrEqualTo 42attr >= 42
attr lessThan 42attr < 42
attr lessThanOrEqualTo 42attr <= 42
attr.between(lower, upper)attr BETWEEN { lower, upper }

Compound predicates​

FunctionJoins clauses withNotes
anyOf { }ORResult is grouped in parentheses
allOf { }ANDUseful for explicit grouping inside anyOf
not { }NOT (...)Negates the clause(s) inside the block
// OR grouping
val done by iOSNSPredicate(nsPredicate {
anyOf {
name equalTo "done"
value equalTo "done"
}
type isIn listOf(XCUIElementType.BUTTON, XCUIElementType.KEY)
})
// Produces: (name == 'done' OR value == 'done') AND type IN {'XCUIElementTypeButton', 'XCUIElementTypeKey'}

// Negation + rect
val offscreen by iOSNSPredicate(nsPredicate {
rect.x.between(1, 100)
not { isVisible equalTo true }
})
// Produces: rect.x BETWEEN { 1, 100 } AND NOT (visible == true)

// Nested allOf inside anyOf
val submit by iOSNSPredicate(nsPredicate {
anyOf {
allOf {
name equalTo "done"
isEnabled equalTo true
}
label equalTo "cancel"
}
})
// Produces: ((name == 'done' AND enabled == true) OR label == 'cancel')