我的角度应用程序中有一个 e2e 量角器测试。我刚刚连续几次运行完全相同的测试,它通过了大约 5% 的时间,失败并出现下面屏幕截图中的错误。
考试:
it('should open the cart with the cart button in the header', () => {
page.navigateTo('/calendar/day/(dmy:27-9-2018)');
page.cartButton().click();
expect(element(by.css('h2.cart-header')).isPresent()).toBe(true);
});
量角器暂停启动的 chrome 实例显示该按钮已被单击并且 h2 元素存在(参见底部的图像)。
我试过的
- 我已经用模拟数据替换了这个组件中的数据,以消除异步操作
- 我禁用了动画
- 我试图使它成为一个异步函数:
... header', async () => { ... - 我试过 await(ing) 元素:
expect(await element(by.css('h2.cart... - 我试过
browser.sleep(1000) - 我尝试了各种断言,例如
.toBe(true),.toEqual(true)和.toBeTruthy()
是什么导致了这个错误,我该如何解决?

