kibana/test/functional/services/flyout.ts
Kibana Machine 52284a3ec3
[8.9] Ftr/speedup dashboard tests (#160722) (#160791)
# Backport

This will backport the following commits from `main` to `8.9`:
- [Ftr/speedup dashboard tests
(#160722)](https://github.com/elastic/kibana/pull/160722)

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

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

<!--BACKPORT [{"author":{"name":"Dzmitry
Lemechko","email":"dzmitry.lemechko@elastic.co"},"sourceCommit":{"committedDate":"2023-06-28T16:49:32Z","message":"Ftr/speedup
dashboard tests (#160722)\n\n## Summary\r\n\r\nWhile splitting
`test/functional/apps/dashboard/group2/config.ts` in\r\n#160612, I
noticed that some tests (`it` function level) takes 30-45\r\nseconds
though having little actions to do in Kibana.\r\n\r\nAfter closer look I
found that:\r\n- `await PageObjects.dashboard.clickNewDashboard();` call
takes ~13-15\r\nseconds when dashboard is empty\r\n- `await
dashboardAddPanel.closeAddPanel();` call takes ~12 seconds when\r\nthere
are no flyouts displayed\r\n\r\nExpected improvement:\r\n- `await
PageObjects.dashboard.clickNewDashboard()` call takes **2**\r\nseconds,
used **103** times in tests.\r\n- `await
dashboardAddPanel.closeAddPanel()` call takes **3** seconds,\r\nused
**21** times in tests.\r\n\r\nPR FTR configs runtime\r\n<img
width=\"778\"
alt=\"image\"\r\nsrc=\"673fee19-91ef-4bc3-9848-5f844b42774c\">\r\n\r\n`main`
branch last 3 days avg configs runtime\r\n<img width=\"1555\"
alt=\"image\"\r\nsrc=\"6e364cb9-c786-411a-9491-a749351f4c94\">\r\n\r\n\r\n\r\nflaky
test runner 50x for 6 most affected
configs\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2519","sha":"54fddef2dbdf7cbd18c54a4f3b0810e44394eb54","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.9.0","v8.8.2","v8.10.0"],"number":160722,"url":"https://github.com/elastic/kibana/pull/160722","mergeCommit":{"message":"Ftr/speedup
dashboard tests (#160722)\n\n## Summary\r\n\r\nWhile splitting
`test/functional/apps/dashboard/group2/config.ts` in\r\n#160612, I
noticed that some tests (`it` function level) takes 30-45\r\nseconds
though having little actions to do in Kibana.\r\n\r\nAfter closer look I
found that:\r\n- `await PageObjects.dashboard.clickNewDashboard();` call
takes ~13-15\r\nseconds when dashboard is empty\r\n- `await
dashboardAddPanel.closeAddPanel();` call takes ~12 seconds when\r\nthere
are no flyouts displayed\r\n\r\nExpected improvement:\r\n- `await
PageObjects.dashboard.clickNewDashboard()` call takes **2**\r\nseconds,
used **103** times in tests.\r\n- `await
dashboardAddPanel.closeAddPanel()` call takes **3** seconds,\r\nused
**21** times in tests.\r\n\r\nPR FTR configs runtime\r\n<img
width=\"778\"
alt=\"image\"\r\nsrc=\"673fee19-91ef-4bc3-9848-5f844b42774c\">\r\n\r\n`main`
branch last 3 days avg configs runtime\r\n<img width=\"1555\"
alt=\"image\"\r\nsrc=\"6e364cb9-c786-411a-9491-a749351f4c94\">\r\n\r\n\r\n\r\nflaky
test runner 50x for 6 most affected
configs\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2519","sha":"54fddef2dbdf7cbd18c54a4f3b0810e44394eb54"}},"sourceBranch":"main","suggestedTargetBranches":["8.9","8.8"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/160722","number":160722,"mergeCommit":{"message":"Ftr/speedup
dashboard tests (#160722)\n\n## Summary\r\n\r\nWhile splitting
`test/functional/apps/dashboard/group2/config.ts` in\r\n#160612, I
noticed that some tests (`it` function level) takes 30-45\r\nseconds
though having little actions to do in Kibana.\r\n\r\nAfter closer look I
found that:\r\n- `await PageObjects.dashboard.clickNewDashboard();` call
takes ~13-15\r\nseconds when dashboard is empty\r\n- `await
dashboardAddPanel.closeAddPanel();` call takes ~12 seconds when\r\nthere
are no flyouts displayed\r\n\r\nExpected improvement:\r\n- `await
PageObjects.dashboard.clickNewDashboard()` call takes **2**\r\nseconds,
used **103** times in tests.\r\n- `await
dashboardAddPanel.closeAddPanel()` call takes **3** seconds,\r\nused
**21** times in tests.\r\n\r\nPR FTR configs runtime\r\n<img
width=\"778\"
alt=\"image\"\r\nsrc=\"673fee19-91ef-4bc3-9848-5f844b42774c\">\r\n\r\n`main`
branch last 3 days avg configs runtime\r\n<img width=\"1555\"
alt=\"image\"\r\nsrc=\"6e364cb9-c786-411a-9491-a749351f4c94\">\r\n\r\n\r\n\r\nflaky
test runner 50x for 6 most affected
configs\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2519","sha":"54fddef2dbdf7cbd18c54a4f3b0810e44394eb54"}}]}]
BACKPORT-->

Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>
2023-06-28 11:03:32 -07:00

47 lines
1.8 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { FtrService } from '../ftr_provider_context';
export class FlyoutService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly find = this.ctx.getService('find');
private readonly log = this.ctx.getService('log');
private readonly retry = this.ctx.getService('retry');
public async close(dataTestSubj: string): Promise<void> {
this.log.debug('Closing flyout', dataTestSubj);
const flyoutElement = await this.testSubjects.find(dataTestSubj);
await this.retry.try(async () => {
const closeBtn = await flyoutElement.findByCssSelector('[aria-label*="Close"]');
await closeBtn.click();
await this.testSubjects.missingOrFail(dataTestSubj);
});
}
public async ensureClosed(dataTestSubj: string): Promise<void> {
if (await this.testSubjects.exists(dataTestSubj, { timeout: 1000 })) {
await this.close(dataTestSubj);
}
}
public async ensureAllClosed(): Promise<void> {
await this.retry.waitFor('all flyouts to be closed', async () => {
let flyoutElements = await this.find.allByCssSelector('.euiFlyout', 2500);
if (!flyoutElements.length) {
return true;
}
for (let i = 0; i < flyoutElements.length; i++) {
const closeBtn = await flyoutElements[i].findByCssSelector('[aria-label*="Close"]');
await closeBtn.click();
}
flyoutElements = await this.find.allByCssSelector('.euiFlyout', 500);
return flyoutElements.length === 0;
});
}
}