diff --git a/test/functional/services/toasts.ts b/test/functional/services/toasts.ts index b40d30f5aa27d..ea105eb82fa93 100644 --- a/test/functional/services/toasts.ts +++ b/test/functional/services/toasts.ts @@ -6,10 +6,12 @@ * Side Public License, v 1. */ +import expect from '@kbn/expect'; import { FtrService } from '../ftr_provider_context'; export class ToastsService extends FtrService { private readonly testSubjects = this.ctx.getService('testSubjects'); + private readonly retry = this.ctx.getService('retry'); /** * Returns the title and message of a specific error toast. @@ -62,6 +64,23 @@ export class ToastsService extends FtrService { } } + public async dismissAllToastsWithChecks() { + await this.retry.tryForTime(30 * 1000, async () => { + await this.dismissAllToasts(); + await this.assertToastCount(0); + }); + } + + public async assertToastCount(expectedCount: number) { + await this.retry.tryForTime(5 * 1000, async () => { + const toastCount = await this.getToastCount({ timeout: 1000 }); + expect(toastCount).to.eql( + expectedCount, + `Toast count should be ${expectedCount} (got ${toastCount})` + ); + }); + } + public async getToastElement(index: number) { const list = await this.getGlobalToastList(); return await list.findByCssSelector(`.euiToast:nth-child(${index})`); @@ -77,13 +96,13 @@ export class ToastsService extends FtrService { return await list.findAllByCssSelector(`.euiToast`); } - private async getGlobalToastList() { - return await this.testSubjects.find('globalToastList'); + private async getGlobalToastList(options?: { timeout?: number }) { + return await this.testSubjects.find('globalToastList', options?.timeout); } - public async getToastCount() { - const list = await this.getGlobalToastList(); - const toasts = await list.findAllByCssSelector(`.euiToast`); + public async getToastCount(options?: { timeout?: number }) { + const list = await this.getGlobalToastList(options); + const toasts = await list.findAllByCssSelector(`.euiToast`, options?.timeout); return toasts.length; } } diff --git a/x-pack/test/functional/services/ml/stack_management_jobs.ts b/x-pack/test/functional/services/ml/stack_management_jobs.ts index 67daafb108868..eeb2d867d14f3 100644 --- a/x-pack/test/functional/services/ml/stack_management_jobs.ts +++ b/x-pack/test/functional/services/ml/stack_management_jobs.ts @@ -357,8 +357,7 @@ export function MachineLearningStackManagementJobsProvider({ const title: string = await titleElement.getVisibleText(); expect(title).to.match(/^Your file is downloading in the background$/); - const dismissButton = await testSubjects.findDescendant('toastCloseButton', resultToast); - await dismissButton.click(); + await toasts.dismissAllToastsWithChecks(); // check that the flyout is closed await testSubjects.missingOrFail('mlJobMgmtExportJobsFlyout', { timeout: 60 * 1000 });