testID; an object
combines conditions, and an element matches when all of them hold. Matchers are the same on iOS, Android
and the web.
testID is rendered as data-testid; matchers do not change.
Matcher fields
id
The testID: an exact string or a regular expression. 'save' is short for { id: 'save' }.
text
The displayed text: an exact string or a regular expression. It matches the deepest element whose own
text matches, so a button and the label inside it do not both match.
label
The accessibility label: accessibilityLabel on iOS / Android, aria-label on the web. An exact string
or a regular expression.
role
The accessibility role: accessibilityRole on iOS / Android, role on the web.
type
What kind of element it is. Either a semantic type, the same on every platform, or a
host type ('RCTView', 'div'), or the displayName of a component that renders the element.
has
The element has a descendant that matches this matcher (Detox withDescendant).
not
Leaves out elements that match this matcher.
within
The element is inside the single element matched by this matcher (Detox withAncestor).
index
The n-th match, counting from 0, in render order. The order is the same on every platform (Detox’s
atIndex order differs between iOS and Android).
Semantic types
type accepts these platform-independent kinds. They come from the accessibility role first, then from
the host component, so they also work in release builds where component names are minified.
Switch is a <div> around
an <input role="switch">: { type: 'switch' } matches the outer element, which also reports the input’s
checked state, value, focus, disabled state and label.
Visibility
Actions andexpectVisible need a visible element. An element is visible when:
- neither it nor an ancestor is hidden by style (
display: none,opacity: 0), and - part of it is on screen: inside the window and inside every ancestor that clips its content (scroll
views,
overflowother thanvisible).
visibleRatio (element summary) is the visible fraction of its
area.
An element on a screen that is not on top is not visible either: on iOS / Android a native stack keeps the
screens below in place, covered by the later one (unless it is presented as a transparent modal), and
inactive tab screens are detached.
Being covered by another element is not part of visibility. Actions check that separately and fail with
ELEMENT_OBSCURED (finding elements).
(current route: /students/new).