Detox uses matchers to match UI elements in your app and expectations to verify those elements are in the expected state.
Use actions to simulate use interaction with elements.
.toBeVisible()
.toExist()
.toHaveText()
.toHaveLabel()
.toHaveId()
.toHaveValue()
.toHaveSliderPosition()
iOS only.toHaveToggleValue()
.not
.withTimeout()
Expects the element to be visible on screen.
On iOS, visibility is defined by having the view, or one of its subviews, be topmost at the view's activation point on screen.
await expect(element(by.id('UniqueId204'))).toBeVisible();
Expects the element to exist within the app’s current UI hierarchy.
await expect(element(by.id('UniqueId205'))).toExist();
Expects the element to have the specified text.
await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text');
Expects the element to have the specified label as its accessibility label (iOS) or content description (Android). In React Native, this corresponds to the value in the accessibilityLabel
prop.
await expect(element(by.id('UniqueId204'))).toHaveLabel('Done');
Expects the element to have the specified accessibility identifier. In React Native, this corresponds to the value in the testID
prop.
await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204');
Expects the element to have the specified accessibility value. In React Native, this corresponds to the value in the accessibilityValue
prop.
await expect(element(by.id('UniqueId533'))).toHaveValue('0');
Expects the slider element to have the specified normalized position ([0, 1]), within the provided tolerance (optional).
await expect(element(by.id('slider'))).toHaveSliderPosition(0.75);
await expect(element(by.id('slider'))).toHaveSliderPosition(0.3113, 0.00001);
Expects a toggle-able element (e.g. a Switch or a Check-Box) to be on/checked or off/unchecked. As a reference, in react-native, this is the equivalent switch component.
await expect(element(by.id('switch'))).toHaveToggleValue(true);
await expect(element(by.id('checkbox'))).toHaveToggleValue(false);
Negates the expectation.
await expect(element(by.id('UniqueId533'))).not.toBeVisible();
Waits until the expectation is resolved for the specified amount of time. If timeout is reached before resolution, the expectation is failed.
timeout
—the timeout to wait, in ms
await waitFor(element(by.id('UniqueId204'))).toBeVisible().withTimeout(2000);
Deprecated: Use .not.toBeVisible()
instead.
Expects the element to not be visible on screen.
await expect(element(by.id('UniqueId205'))).toBeNotVisible();
Deprecated: Use .not.toExist()
instead.
Expects the element to not exist within the app’s current UI hierarchy.
await expect(element(by.id('RandomJunk959'))).toNotExist();