Detox: iOS Simulator how to confirm alert message
You can now press on native dialogs. Tested on iOS. (did not test on Android)
If your button says "OK" ie:
Alert.alert(
`Are you sure you would like to remove this image as the coming soon image?`,
undefined,
[
{
text: "No",
style: "cancel",
},
{
text: "OK",
style: "destructive",
onPress: this.onRemoveHero,
},
]
);
You would click this by doing:
element(by.label("OK")).atIndex(0).tap();
It should work with finding element by text
await element(by.text('Log out')).tap();
Demo repo: https://github.com/FDiskas/demonas/blob/c703840a991b2f3d96a18ac8c5120ee1d5f901f8/e2e/firstTest.spec.ts#L11
After some tinkering I ended up using this:
await element(by.label('Log out').and(by.type('_UIAlertControllerActionView'))).tap();
Not sure if this will work for every iOS version, but seem to work on 10.3 and 11.1
Use View Hierarchy Debugger provided by Xcode to see if the type has changed for a different version of iOS.