TestIDs
Ids of the views the navigation shows without an id from the app, for end-to-end tests (Detox, Maestro, Appium) to find them by.
import { TestIDs } from '@apexnative/navigation';
TestIDs holds the ids of the views the navigation draws without an id from the app, so that an end-to-end test
(Detox, Maestro, Appium) can find them. The app's own content takes testID as in any React Native app; the bars,
the buttons and the tabs take theirs from the options. What is left is here.
Usage
An end-to-end test runs outside the app, so it uses the string the constant holds:
it('opens Details and goes back', async () => {
await element(by.text('Open details')).tap();
await expect(element(by.id('details.topBar'))).toBeVisible();
await element(by.id('BackButton')).tap();
await expect(element(by.text('Open details'))).toBeVisible();
});
Code that runs inside the app, or shares constants with the tests, imports it instead of repeating the string:
import { TestIDs } from '@apexnative/navigation';
TestIDs.backButton; // 'BackButton'
Signature
const TestIDs: { readonly backButton: "BackButton"; }
The ids
backButton
backButton: "BackButton"
"BackButton" Required.PlatformsiOSiPadOSAndroidThe back button of a stack's top bar: 'BackButton'. The platform draws it, not the app, so the app can't give it a
testID in its content.
- iOS It is UIKit's own back button, and UIKit gives it this id. There is no public way to set another.
- Android The navigation gives it the same id, so one test serves both platforms. A screen sets another
in its options:
s.backButton({ testID: 'details.back' }).
When two stacks show at once, such as the columns of a split view, two back buttons have the id. Find the one in the
top bar of the screen, by the bar's testID:
await element(
by.id('BackButton').withAncestor(by.id('details.topBar')),
).tap();
See also
- Testing: the ids of the bars, buttons and tabs, screens in Jest, what only a device checks.
- Back and gestures: the back button and its options.