量角器在等待条件失败后重试函数



我有一些不稳定的测试,我正在尝试修复。 量角器:5.3.2 角度 6

这就是我要做的:

  1. 加载页面(数据应从数据库加载(
  2. 等到满足条件:数据加载且加载微调器不可见
  3. 如果不满足条件重试,请重新加载页面

这是我的代码:

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

知道我该如何实现这一目标吗?我知道有量角器片和重试 npm 包,但它们并不完全是我需要的。

我的问题解决为:

navigate(): promise.Promise<any> {
return browser.get('/').then(async () => {
let waitForCondition = this.waitForDataToLoad(10000)
.then((found) => {
return Promise.resolve(found);
})
.catch((error) => {
if (this.retryAttempts < 4) {
console.log(`Retrying navigate, attempt: ${this.retryAttempts}.`);
this.navigate();
} else {
console.log('Rejecting the promise after 3 attempts.');
return Promise.reject(error);
}
});;
this.retryAttempts++;
return waitForCondition;
});

}

waitForDataToLoad(timeOut?: number): promise.Promise<{}> {
let isSpinnerInVisible =  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)
}

相关内容

  • 没有找到相关文章

最新更新