排毒:只有存在时点按按钮

时间:2017-10-03 17:22:47

标签: 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();
});

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

https://github.com/wix/detox

2 个答案:

答案 0 :(得分:2)

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

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
});

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

答案 1 :(得分:0)

我怀疑我们可以在toExist上使用此模式

it('should be in home menu', async () => {
  await waitFor(element(by.id('cancelUpgrade')))
    .toBeVisible()
    .withTimeout(2000);
  try {
    await expect(element(by.id('cancelUpgrade'))).toExist();
  } catch (e) {}
  // continue your tests
});

如果您不需要等待:

it('should be in home menu', async () => {
  try {
    await expect(element(by.id('cancelUpgrade'))).toExist();
  } catch (e) {}
  // continue your tests
});