提交 e4601b2a 编写于 作者: M Michel Kaporin

Simplified element waiting code.

上级 e57d3958
......@@ -82,7 +82,7 @@ export class SpectronApplication {
}
public waitFor(func: (...args: any[]) => any, args: any): Promise<any> {
return this.callClientAPI(func, args, 0);
return this.callClientAPI(func, args);
}
public wait(): Promise<any> {
......@@ -110,39 +110,28 @@ export class SpectronApplication {
});
}
private callClientAPI(func: (...args: any[]) => Promise<any>, args: any, trial: number): Promise<any> {
if (trial > this.pollTrials) {
return Promise.reject(`Could not retrieve the element in ${this.testRetry * this.pollTrials * this.pollTimeout} seconds.`);
}
private callClientAPI(func: (...args: any[]) => Promise<any>, args: any): Promise<any> {
let trial = 1;
return new Promise(async (res, rej) => {
let resolved = false, capture = false;
while (true) {
if (trial > this.pollTrials) {
rej(`Could not retrieve the element in ${this.testRetry * this.pollTrials * this.pollTimeout} seconds.`);
break;
}
const tryCall = async (resolve: any, reject: any): Promise<any> => {
await this.wait();
let result;
try {
const result = await this.callClientAPI(func, args, ++trial);
res(result);
} catch (error) {
rej(error);
}
}
result = await func.call(this.client, args);
} catch (e) {}
try {
const result = await func.call(this.client, args, capture);
if (!resolved && result === '') {
resolved = true;
await tryCall(res, rej);
} else if (!resolved) {
resolved = true;
if (result && result !== '') {
await this.screenshot.capture();
res(result);
break;
}
} catch (e) {
if (!resolved) {
resolved = true;
await tryCall(res, rej);
}
this.wait();
trial++;
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册