Skip to content

Commit

Permalink
Move retry logiv to find.existsByDisplayedByCssSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyos committed Oct 23, 2019
1 parent e8121ac commit b284bb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 16 additions & 4 deletions test/functional/services/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,22 @@ export async function FindProvider({ getService }: FtrProviderContext) {
timeout: number = WAIT_FOR_EXISTS_TIME
): Promise<boolean> {
log.debug(`Find.existsByDisplayedByCssSelector('${selector}') with timeout=${timeout}`);
return await this.exists(async drive => {
const elements = wrapAll(await drive.findElements(By.css(selector)));
return await this.filterElementIsDisplayed(elements);
}, timeout);
try {
await retry.tryForTime(timeout, async () => {
// make sure that the find timeout is not longer than the retry timeout
await this._withTimeout(Math.min(timeout, WAIT_FOR_EXISTS_TIME));
const elements = await driver.findElements(By.css(selector));
await this._withTimeout(defaultFindTimeout);
const displayed = await this.filterElementIsDisplayed(wrapAll(elements));
if (displayed.length === 0) {
throw new Error(`${selector} is not displayed`);
}
});
} catch (err) {
await this._withTimeout(defaultFindTimeout);
return false;
}
return true;
}

public async existsByCssSelector(
Expand Down
9 changes: 3 additions & 6 deletions test/functional/services/test_subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
selector: string,
existsOptions?: ExistsOptions
): Promise<void | never> {
const options = { timeout: TRY_TIME, ...existsOptions };
await retry.tryForTime(options.timeout, async () => {
if (!(await this.exists(selector, options))) {
throw new Error(`expected testSubject(${selector}) to exist`);
}
});
if (!(await this.exists(selector, { timeout: TRY_TIME, ...existsOptions }))) {
throw new Error(`expected testSubject(${selector}) to exist`);
}
}

public async missingOrFail(
Expand Down

0 comments on commit b284bb9

Please sign in to comment.