mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
cd81a9e9d8
commit
0f61756fce
2 changed files with 25 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue