[ftr/services] move WAIT_FOR_EXISTS_TIME into config (#28630) (#28699)

This commit is contained in:
Spencer 2019-01-14 11:45:55 -08:00 committed by GitHub
parent 3062069d52
commit 9a5157ce7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 21 deletions

View file

@ -84,6 +84,21 @@ export const schema = Joi.object().keys({
esRequestTimeout: Joi.number().default(30000),
kibanaStabilize: Joi.number().default(15000),
navigateStatusPageCheck: Joi.number().default(250),
// 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.
waitForExists: Joi.number().default(2500),
}).default(),
mochaOpts: Joi.object().keys({

View file

@ -19,27 +19,13 @@
import { LeadfootElementWrapper } from './lib/leadfoot_element_wrapper';
// 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');
const leadfoot = getService('__leadfoot__');
const retry = getService('retry');
const WAIT_FOR_EXISTS_TIME = config.get('timeouts.waitForExists');
const defaultFindTimeout = config.get('timeouts.find');
const wrap = leadfootElement => (

View file

@ -24,15 +24,15 @@ 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');
const browser = getService('browser');
const find = getService('find');
const config = getService('config');
const defaultFindTimeout = config.get('timeouts.find');
const FIND_TIME = config.get('timeouts.find');
const WAIT_FOR_EXISTS_TIME = config.get('timeouts.waitForExists');
class TestSubjects {
async exists(selector, timeout = WAIT_FOR_EXISTS_TIME) {
@ -65,17 +65,17 @@ export function TestSubjectsProvider({ getService }) {
});
}
async clickWhenNotDisabled(selector, { timeout } = { timeout: defaultFindTimeout }) {
async clickWhenNotDisabled(selector, { timeout = FIND_TIME } = {}) {
log.debug(`TestSubjects.click(${selector})`);
await find.clickByCssSelectorWhenNotDisabled(testSubjSelector(selector), { timeout });
}
async click(selector, timeout = defaultFindTimeout) {
async click(selector, timeout = FIND_TIME) {
log.debug(`TestSubjects.click(${selector})`);
await find.clickByCssSelector(testSubjSelector(selector), timeout);
}
async doubleClick(selector, timeout = defaultFindTimeout) {
async doubleClick(selector, timeout = FIND_TIME) {
log.debug(`TestSubjects.doubleClick(${selector})`);
return await retry.try(async () => {
const element = await this.find(selector, timeout);