Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Extend the timeout used to check if something exists. (#24140) #24234

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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