在我的测试中,我想模拟" 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.
答案 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
});