[Dashboard] Fix flaky snapshot test (#169415)

Closes https://github.com/elastic/kibana/issues/167942

## Summary

This PR fixes the attached flaky test by ensuring that everything on the
page has loaded before taking the snapshot. Because these snapshot tests
are on an empty dashboard, the previous call to `waitForRenderComplete`
(which ensures each **panel** has been rendered/loaded) didn't actually
do anything; so, I replaced it with individual `waitFor` calls that
ensure the dashboard is in (approximately) the correct state before the
screenshot is taken.

### [Flaky Test
Runner](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3632)


![image](e4a406ec-336b-4321-b933-c3948bb90956)

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This commit is contained in:
Hannah Mudge 2023-10-19 14:26:11 -06:00 committed by GitHub
parent dce8eedf56
commit b8ecaa22d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,8 @@ export default function ({
const kibanaServer = getService('kibanaServer');
const dashboardPanelActions = getService('dashboardPanelActions');
const dashboardAddPanel = getService('dashboardAddPanel');
const testSubjects = getService('testSubjects');
const retry = getService('retry');
describe('dashboard snapshots', function describeIndexTests() {
before(async function () {
@ -96,6 +98,15 @@ export default function ({
});
describe('compare controls snapshot', async () => {
const waitForPageReady = async () => {
await PageObjects.header.waitUntilLoadingHasFinished();
await retry.waitFor('page ready for screenshot', async () => {
const queryBarVisible = await testSubjects.exists('globalQueryBar');
const controlGroupVisible = await testSubjects.exists('controls-group-wrapper');
return queryBarVisible && controlGroupVisible;
});
};
before(async () => {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();
@ -115,6 +126,7 @@ export default function ({
});
it('in light mode', async () => {
await waitForPageReady();
const percentDifference = await screenshot.compareAgainstBaseline(
'dashboard_controls_light',
updateBaselines
@ -127,8 +139,7 @@ export default function ({
'theme:darkMode': true,
});
await browser.refresh();
await PageObjects.dashboard.waitForRenderComplete();
await waitForPageReady();
const percentDifference = await screenshot.compareAgainstBaseline(
'dashboard_controls_dark',
updateBaselines