排毒:仅当存在时才点击按钮

Pau*_*aul 4 javascript testing automated-tests detox

在我的测试中,我只想在“cancelUpgrade”按钮显示时模拟点击:

it('should be in home menu', async () => {
  await waitFor(element(by.id('cancelUpgrade')))
    .toBeVisible()
    .withTimeout(2000);
  await element(by.id('cancelUpgrade')).tap();
});
Run Code Online (Sandbox Code Playgroud)

它返回预期的错误 Error: Cannot find UI element.

https://github.com/wix/detox

Pau*_*aul 7

您可以将 tap 包裹在 try/catch 块中:

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
});
Run Code Online (Sandbox Code Playgroud)

不是最好的方法,但我认为这是目前排毒中可能的方法。