In my test, I would like to simulate a tap in the "cancelUpgrade" button only if it is displayed:
it('should be in home menu', async () => {
await waitFor(element(by.id('cancelUpgrade')))
.toBeVisible()
.withTimeout(2000);
await element(by.id('cancelUpgrade')).tap();
});
It returns the expected error Error: Cannot find UI element.
You can wrap tap in the try/catch block:
it('should be in home menu', async () => {
await waitFor(element(by.id('cancelUpgrade')))
.toBeVisible()
.withTimeout(2000);
try {
await element(by.id('cancelUpgrade')).tap();
} catch (e) {}
// continue your tests
});
Not the best way but i think that's what currently possible within detox.