Skip to content

Commit

Permalink
Extend the timeout used to check if something exists. (elastic#24140)
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon authored Oct 18, 2018
1 parent a2172b9 commit db77feb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 20 additions & 5 deletions test/functional/services/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions test/functional/services/test_subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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.
Expand Down

0 comments on commit db77feb

Please sign in to comment.