From 0f61756fcebacb880f6cfec64a53807efcd642d7 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Fri, 19 Oct 2018 16:09:24 -0400 Subject: [PATCH] Extend the timeout used to check if something exists. (#24140) (#24234) --- test/functional/services/find.js | 25 ++++++++++++++++++----- test/functional/services/test_subjects.js | 8 +++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/test/functional/services/find.js b/test/functional/services/find.js index 848fc36fe25f6..e3e99998051b7 100644 --- a/test/functional/services/find.js +++ b/test/functional/services/find.js @@ -17,6 +17,21 @@ * under the License. */ +// Many of our tests use the `exists` functions to determine where the user is. For +// example, you'll see a lot of code like: +// if (!testSubjects.exists('someElementOnPageA')) { +// navigateToPageA(); +// } +// If the element doesn't exist, selenium would wait up to defaultFindTimeout for it to +// appear. Because there are many times when we expect it to not be there, we don't want +// to wait the full amount of time, or it would greatly slow our tests down. We used to have +// this value at 1 second, but this caused flakiness because sometimes the element was deemed missing +// only because the page hadn't finished loading. +// The best path forward it to prefer functions like `testSubjects.existOrFail` or +// `testSubjects.missingOrFail` instead of just the `exists` checks, and be deterministic about +// where your user is and what they should click next. +export const WAIT_FOR_EXISTS_TIME = 2500; + export function FindProvider({ getService }) { const log = getService('log'); const config = getService('config'); @@ -115,7 +130,7 @@ export function FindProvider({ getService }) { return await this.allByCustom(remote => remote.findAllByCssSelector(selector), timeout); } - async descendantExistsByCssSelector(selector, parentElement, timeout = 1000) { + async descendantExistsByCssSelector(selector, parentElement, timeout = WAIT_FOR_EXISTS_TIME) { log.debug('Find.descendantExistsByCssSelector: ' + selector); return await this.exists(async () => await parentElement.findDisplayedByCssSelector(selector), timeout); } @@ -161,7 +176,7 @@ export function FindProvider({ getService }) { }); } - async exists(findFunction, timeout = 1000) { + async exists(findFunction, timeout = WAIT_FOR_EXISTS_TIME) { return await this._withTimeout(timeout, async remote => { try { await findFunction(remote); @@ -172,17 +187,17 @@ export function FindProvider({ getService }) { }); } - async existsByLinkText(linkText, timeout = 1000) { + async existsByLinkText(linkText, timeout = WAIT_FOR_EXISTS_TIME) { log.debug(`existsByLinkText ${linkText}`); return await this.exists(async remote => await remote.findDisplayedByLinkText(linkText), timeout); } - async existsByDisplayedByCssSelector(selector, timeout = 1000) { + async existsByDisplayedByCssSelector(selector, timeout = WAIT_FOR_EXISTS_TIME) { log.debug(`existsByDisplayedByCssSelector ${selector}`); return await this.exists(async remote => await remote.findDisplayedByCssSelector(selector), timeout); } - async existsByCssSelector(selector, timeout = 1000) { + async existsByCssSelector(selector, timeout = WAIT_FOR_EXISTS_TIME) { log.debug(`existsByCssSelector ${selector}`); return await this.exists(async remote => await remote.findByCssSelector(selector), timeout); } diff --git a/test/functional/services/test_subjects.js b/test/functional/services/test_subjects.js index 7e3ad0613b919..c6d0361a4f48c 100644 --- a/test/functional/services/test_subjects.js +++ b/test/functional/services/test_subjects.js @@ -24,6 +24,8 @@ import { map as mapAsync, } from 'bluebird'; +import { WAIT_FOR_EXISTS_TIME } from './find'; + export function TestSubjectsProvider({ getService }) { const log = getService('log'); const retry = getService('retry'); @@ -33,12 +35,12 @@ export function TestSubjectsProvider({ getService }) { const defaultFindTimeout = config.get('timeouts.find'); class TestSubjects { - async exists(selector, timeout = 1000) { + async exists(selector, timeout = WAIT_FOR_EXISTS_TIME) { log.debug(`TestSubjects.exists(${selector})`); return await find.existsByDisplayedByCssSelector(testSubjSelector(selector), timeout); } - async existOrFail(selector, timeout = 1000) { + async existOrFail(selector, timeout = WAIT_FOR_EXISTS_TIME) { await retry.try(async () => { log.debug(`TestSubjects.existOrFail(${selector})`); const doesExist = await this.exists(selector, timeout); @@ -47,7 +49,7 @@ export function TestSubjectsProvider({ getService }) { }); } - async missingOrFail(selector, timeout = 1000) { + async missingOrFail(selector, timeout = WAIT_FOR_EXISTS_TIME) { log.debug(`TestSubjects.missingOrFail(${selector})`); const doesExist = await this.exists(selector, timeout); // Verify element is missing, or else fail the test consuming this.