From b284bb91c4c30d8f50a81bd4efaa1d6233d63b29 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Wed, 23 Oct 2019 15:31:11 +0200 Subject: [PATCH] Move retry logiv to find.existsByDisplayedByCssSelector --- test/functional/services/find.ts | 20 ++++++++++++++++---- test/functional/services/test_subjects.ts | 9 +++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/test/functional/services/find.ts b/test/functional/services/find.ts index c65821ea73ace..312668b718dc0 100644 --- a/test/functional/services/find.ts +++ b/test/functional/services/find.ts @@ -303,10 +303,22 @@ export async function FindProvider({ getService }: FtrProviderContext) { timeout: number = WAIT_FOR_EXISTS_TIME ): Promise { 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( diff --git a/test/functional/services/test_subjects.ts b/test/functional/services/test_subjects.ts index 483c3cb87b3d1..a3f64e6f96cc8 100644 --- a/test/functional/services/test_subjects.ts +++ b/test/functional/services/test_subjects.ts @@ -56,12 +56,9 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) { selector: string, existsOptions?: ExistsOptions ): Promise { - 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(