Skip to content

Commit

Permalink
[8.8] [ML] Functional tests - stabilize export job tests (#156586) (#…
Browse files Browse the repository at this point in the history
…156790)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[ML] Functional tests - stabilize export job tests
(#156586)](#156586)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Robert
Oskamp","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-05-05T07:17:04Z","message":"[ML]
Functional tests - stabilize export job tests (#156586)\n\nThis PR
stabilizes the export job tests by making sure the export\r\nsuccess
toast is closed before moving on to the next test. As part of\r\nthat,
the toasts service got two new methods\r\n`dismissAllToastsWithChecks`
and
`assertToastCount`.","sha":"dd1fd2647a453fe9ad233d3afc9848b507c945da","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":[":ml","release_note:skip","backport:prev-minor","v8.8.0","v8.9.0"],"number":156586,"url":"https://github.com/elastic/kibana/pull/156586","mergeCommit":{"message":"[ML]
Functional tests - stabilize export job tests (#156586)\n\nThis PR
stabilizes the export job tests by making sure the export\r\nsuccess
toast is closed before moving on to the next test. As part of\r\nthat,
the toasts service got two new methods\r\n`dismissAllToastsWithChecks`
and
`assertToastCount`.","sha":"dd1fd2647a453fe9ad233d3afc9848b507c945da"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156586","number":156586,"mergeCommit":{"message":"[ML]
Functional tests - stabilize export job tests (#156586)\n\nThis PR
stabilizes the export job tests by making sure the export\r\nsuccess
toast is closed before moving on to the next test. As part of\r\nthat,
the toasts service got two new methods\r\n`dismissAllToastsWithChecks`
and
`assertToastCount`.","sha":"dd1fd2647a453fe9ad233d3afc9848b507c945da"}}]}]
BACKPORT-->

Co-authored-by: Robert Oskamp <[email protected]>
  • Loading branch information
kibanamachine and pheyos authored May 5, 2023
1 parent d762daa commit 36d827a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
29 changes: 24 additions & 5 deletions test/functional/services/toasts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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})`);
Expand All @@ -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;
}
}
3 changes: 1 addition & 2 deletions x-pack/test/functional/services/ml/stack_management_jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 36d827a

Please sign in to comment.