【发布时间】:2023-03-03 15:41:02
【问题描述】:
我正在尝试修复一些不稳定的测试。 量角器:5.3.2 角 6
这就是我想要做的:
- 加载页面(数据应从数据库加载)
- 等到满足条件:数据已加载,加载微调器不可见
- 如果不满足条件重试,重新加载页面
这是我的代码:
async navigate(): Promise<void> {
return await browser.get('/', 10000).then(async () => {
return await this.waitForDataToLoad(10000);
});
}
async waitForDataToLoad(timeOut?: number): Promise<any> {
let isSpinnerInVisible = ExpectedConditions.invisibilityOf(element(By.css("spinner")));
let isWorkflowLoaded = ExpectedConditions.visibilityOf(element(By.css("employee-list ul li:first-child a")));
return browser.wait( ExpectedConditions.and(isSpinnerInVisible, isWorkflowLoaded), timeOut, 'data was not loaded in the given timeout');
}
我有几个问题:
1 - 我的自定义超时错误消息永远不会在控制台中打印,它只会将默认错误打印为: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
2- 我尝试如下添加重试功能,但似乎不起作用:
async navigate(): Promise<void> {
return await browser.get('/', 10000).then(async () => {
return await this.waitForDataToLoad(10000);
}, (err) => {
console.log('Data was not loaded:', err.message);
this.navigate(); // Re try
});
}
知道如何实现这一目标吗?我知道有 Protractor flake 和 Retry npm 包,但它们并不是我所需要的。
【问题讨论】:
标签: angular async-await protractor timeout