From 8382b455ef012c83919a2343b647d13d1bd650b7 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Fri, 5 May 2023 09:17:04 +0200 Subject: [PATCH] [ML] Functional tests - stabilize export job tests (#156586) This PR stabilizes the export job tests by making sure the export success toast is closed before moving on to the next test. As part of that, the toasts service got two new methods `dismissAllToastsWithChecks` and `assertToastCount`. (cherry picked from commit dd1fd2647a453fe9ad233d3afc9848b507c945da) --- test/functional/services/toasts.ts | 29 +++++++++++++++---- .../services/ml/stack_management_jobs.ts | 3 +- 2 files changed, 25 insertions(+), 7 deletions(-) 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 });