Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detox: tap button only if exists

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.

https://github.com/wix/detox

like image 670
Paul Avatar asked Oct 03 '17 17:10

Paul


1 Answers

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.

like image 94
Paul Avatar answered Nov 12 '22 17:11

Paul