Skip to content

Commit

Permalink
Extend the timeout used to check if something exists. (#24140) (#24234)
Browse files Browse the repository at this point in the history
stacey-gammon authored Oct 19, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent cd81a9e commit 0f61756
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
@@ -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);
}
8 changes: 5 additions & 3 deletions test/functional/services/test_subjects.js
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 0f61756

Please sign in to comment.