diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/spectron/application.ts index 03cc56070d4abf4871fc37301b171bb1e7362cd1..73e555ffb966aa74899231ed393dc51e081da92b 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/spectron/application.ts @@ -82,7 +82,7 @@ export class SpectronApplication { } public waitFor(func: (...args: any[]) => any, args: any): Promise { - return this.callClientAPI(func, args, 0); + return this.callClientAPI(func, args); } public wait(): Promise { @@ -110,39 +110,28 @@ export class SpectronApplication { }); } - private callClientAPI(func: (...args: any[]) => Promise, args: any, trial: number): Promise { - 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, args: any): Promise { + 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 => { - 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++; } }); }