等待直到使用Typescript在Intern4中加载页面函数?
我有一些关于如何实现等待页面加载等待直到使用Typescript在Intern4中加载页面函数?,typescript,intern,Typescript,Intern,我有一些关于如何实现等待页面加载TypeScript的函数。但有时它不起作用,并抛出timeoutError,即使我在函数中发现了错误。能不能请人复习一下,告诉我有什么问题 以下是我的实现: export abstract class AdvalentBasePage { remote: any; waitTime: number = -1; locator: any; constructor(remote: any, locator: any) {
TypeScript
的函数。但有时它不起作用,并抛出timeoutError
,即使我在函数中发现了错误。能不能请人复习一下,告诉我有什么问题
以下是我的实现:
export abstract class AdvalentBasePage {
remote: any;
waitTime: number = -1;
locator: any;
constructor(remote: any, locator: any) {
this.remote = remote;
this.locator =locator ;
}
abstract getPageTitleXpath(): string;
getPageTitleElement() {
return this.remote.findByXpath(this.getPageTitleXpath());
}
//this function sometimes throws timeoutError even before waitTime provided in argument
async waitUntilPageIsFullyLoaded(waitTime: number): Promise<any> {
this.waitTime = waitTime;
var self = this;
try {
await self.remote.sleep(1000).findByXpath(self.getPageTitleXpath());
} catch (e) {
console.log(e.name)
if (e.name == 'NoSuchElement') {
if (this.waitTime > 0) {
self.waitTime = self.waitTime - 1000;
await self.waitUntilPageIsFullyLoaded(self.waitTime);
}
else {
throw new Error('TimeOut Exception ')
}
}
}
}
}
导出抽象类AdvalentBasePage{
远程:任何;
waitTime:number=-1;
定位器:任何;
构造函数(远程:任意,定位器:任意){
this.remote=远程;
this.locator=定位器;
}
抽象getPageTitleXpath():字符串;
getPageTitleElement(){
返回this.remote.findByXpath(this.getPageTitleXpath());
}
//此函数有时甚至在参数中提供的waitTime之前抛出timeoutError
异步waitUntilPageIsFullyLoaded(waitTime:number):承诺{
this.waitTime=waitTime;
var self=这个;
试一试{
等待self.remote.sleep(1000).findByXpath(self.getPageTitleXpath());
}捕获(e){
console.log(e.name)
如果(e.name='NoSuchElement'){
如果(this.waitTime>0){
self.waitTime=self.waitTime-1000;
等待self.waitUntilPageIsFullyLoaded(self.waitTime);
}
否则{
抛出新错误('超时异常')
}
}
}
}
}
有两种不同的超时:
findBy
调用将超时(取决于浏览器,默认情况下通常为0)this.timeout=x
或this.async(x)
在测试中,x是毫秒数)
看起来您还可以通过简单地设置一个非常大的查找超时来简化方法,而不是创建waitUntilPageIsFullLoaded
方法。例如(假设self
指向测试对象):
// Make sure the test timeout is large enough to handle the time
// required to run all test actions.
self.timeout = 130000;
await self.remote
// Set the find timeout to something huge; this is still efficient
// because the test will continue as soon as an element is found
.setFindTimeout(120000)
.sleep(1000)
.findByXpath(self.getPageTitleXpath())