Skip to content

Commit 418fd49

Browse files
committed
Add retry to find.existsByDisplayedByCssSelector (#48734)
This PR fixes timeout handling in `find.existsByDisplayedByCssSelector` for elements that are found but (not yet) displayed.
1 parent ac66b90 commit 418fd49

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

test/functional/apps/dashboard/dashboard_snapshots.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export default function ({ getService, getPageObjects, updateBaselines }) {
4747
await PageObjects.common.closeToast();
4848

4949
await PageObjects.dashboard.saveDashboard('tsvb');
50-
await PageObjects.common.closeToast();
5150
await PageObjects.dashboard.clickFullScreenMode();
5251
await dashboardPanelActions.openContextMenu();
5352
await dashboardPanelActions.clickExpandPanelToggle();
@@ -68,7 +67,6 @@ export default function ({ getService, getPageObjects, updateBaselines }) {
6867
await PageObjects.common.closeToast();
6968

7069
await PageObjects.dashboard.saveDashboard('area');
71-
await PageObjects.common.closeToast();
7270
await PageObjects.dashboard.clickFullScreenMode();
7371
await dashboardPanelActions.openContextMenu();
7472
await dashboardPanelActions.clickExpandPanelToggle();

test/functional/page_objects/dashboard_page.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
309309

310310
/**
311311
* Save the current dashboard with the specified name and options and
312-
* verify that the save was successful
312+
* verify that the save was successful, close the toast and return the
313+
* toast message
313314
*
314315
* @param dashName {String}
315316
* @param saveOptions {{storeTimeWithDashboard: boolean, saveAsNew: boolean, needsConfirm: false, waitDialogIsClosed: boolean }}
@@ -323,8 +324,11 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
323324

324325
// Confirm that the Dashboard has actually been saved
325326
await testSubjects.existOrFail('saveDashboardSuccess');
327+
const message = await PageObjects.common.closeToast();
326328
await PageObjects.header.waitUntilLoadingHasFinished();
327329
await this.waitForSaveModalToClose();
330+
331+
return message;
328332
}
329333

330334
async waitForSaveModalToClose() {

test/functional/services/find.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,22 @@ export async function FindProvider({ getService }: FtrProviderContext) {
303303
timeout: number = WAIT_FOR_EXISTS_TIME
304304
): Promise<boolean> {
305305
log.debug(`Find.existsByDisplayedByCssSelector('${selector}') with timeout=${timeout}`);
306-
return await this.exists(async drive => {
307-
const elements = wrapAll(await drive.findElements(By.css(selector)));
308-
return await this.filterElementIsDisplayed(elements);
309-
}, timeout);
306+
try {
307+
await retry.tryForTime(timeout, async () => {
308+
// make sure that the find timeout is not longer than the retry timeout
309+
await this._withTimeout(Math.min(timeout, WAIT_FOR_EXISTS_TIME));
310+
const elements = await driver.findElements(By.css(selector));
311+
await this._withTimeout(defaultFindTimeout);
312+
const displayed = await this.filterElementIsDisplayed(wrapAll(elements));
313+
if (displayed.length === 0) {
314+
throw new Error(`${selector} is not displayed`);
315+
}
316+
});
317+
} catch (err) {
318+
await this._withTimeout(defaultFindTimeout);
319+
return false;
320+
}
321+
return true;
310322
}
311323

312324
public async existsByCssSelector(

0 commit comments

Comments
 (0)