This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { protractor } from 'protractor/built/ptor'; | |
import { from, interval, of } from 'rxjs'; | |
import { map, mergeMap, takeWhile } from 'rxjs/operators'; | |
const EC = protractor.ExpectedConditions; | |
/* | |
This is used for evaluation an expression up to x times with y timeout per try | |
Use this to fix fragile expects | |
*/ | |
export class ExpectHelper { | |
public static async expectOrRetry<T>( | |
expectFunc: () => Promise<boolean>, | |
timeout: number = 5000, | |
tryCount: number = 60 | |
): Promise<any> { | |
try { | |
const res = await expectFunc(); | |
if (!res) { | |
throw new Error('Evaluation is false.'); | |
} | |
} catch (error) { | |
if (tryCount > 0) { | |
browser.sleep(timeout); | |
console.log( | |
`Expression failed, retries left: ${tryCount} on expression ${expectFunc.toString()}` | |
); | |
tryCount = tryCount - 1; | |
this.expectOrRetry(expectFunc, timeout, tryCount); | |
} else { | |
// tslint:disable-next-line:no-console | |
console.error(`Error while evaluating expression on ${expectFunc.toString()}`); | |
throw error; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment