Detecting System Dialogs with Detox E2E and React Native

If you are using Detox to run e2e testing for your Android and iOS applications you may have encountered some problems when dealing with native dialogs.

Android Native Dialog

There are number of solutions, but none address the problem cross-platform, and leave you to address it with complicated logic. Until now…

Luke, show me the code!

Alright… alright… the function below will select you native dialogs cross-platform, it returns a Detox element, so it works as a drop-in replacement for element() when selecting native dialogs.

export function systemDialog(label){
if (device.getPlatform() === 'ios') {
return element(by.label(label)).atIndex(0);
}
return element(by.text(label));
}

Add the above function to your project, then it can be used as follows:

await systemDialog('OK').tap();

Hope this helps people addressing the native dialogs in Detox! Happy e2e testing :)

--

--

Luke Brandon Farrell

Luke develops mobile applications using React Native. He writes about component-first architecture and design, code readability, and React Native.