From 04789f86f9a041ca504c346d54813922a950f2ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alfonso=20Mart=C3=ADnez?= Date: Mon, 16 Mar 2020 16:11:10 +0100 Subject: [PATCH] mgr/dashboard: fix notifications E2E tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: https://tracker.ceph.com/issues/44626 Signed-off-by: Alfonso Martínez (cherry picked from commit 418b21ac6f2314edb3fda093db3ef694fa9c7ffe) --- .../dashboard/frontend/e2e/page-helper.po.ts | 4 +-- .../frontend/e2e/ui/notification.e2e-spec.ts | 34 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts index aea78626d8740..4c7fcaf1c1ba8 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts @@ -288,8 +288,8 @@ export abstract class PageHelper { return browser.wait(EC.not(EC.textToBePresentInElement(elem, text)), TIMEOUT, message); } - async waitFn(func: Function, message?: string) { - return browser.wait(func, TIMEOUT, message); + async waitFn(func: Function, message?: string, timeout: number = TIMEOUT) { + return browser.wait(func, timeout, message); } getFirstCell(): ElementFinder { diff --git a/src/pybind/mgr/dashboard/frontend/e2e/ui/notification.e2e-spec.ts b/src/pybind/mgr/dashboard/frontend/e2e/ui/notification.e2e-spec.ts index 52d172a87c65d..3aedae54829db 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/ui/notification.e2e-spec.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/ui/notification.e2e-spec.ts @@ -24,14 +24,27 @@ describe('Notification page', () => { const poolName = 'e2e_notification_pool'; await pools.navigateTo('create'); - await pools.create(poolName, 16); - await pools.edit_pool_pg(poolName, 8, false); + await pools.create(poolName, 8); + await pools.edit_pool_pg(poolName, 4, false); await notification.waitStaleness(notification.getToast()); + // Check that running task is shown. await notification.open(); - await notification.waitVisibility(notification.getTasks().first()); - await expect((await notification.getTasks()).length).toBeGreaterThan(0); + await notification.waitFn(async () => { + const task = await notification.getTasks().first(); + const text = await task.getText(); + return text.includes(poolName); + }, 'Timed out verifying task.'); + // Delete pool after task is complete (otherwise we get an error). + await notification.waitFn( + async () => { + const tasks = await notification.getTasks(); + return tasks.length === 0 ? true : !(await tasks[0].getText()).includes(poolName); + }, + 'Timed out waiting for task to complete.', + 40000 + ); await pools.delete(poolName); }); @@ -44,8 +57,17 @@ describe('Notification page', () => { await notification.waitStaleness(notification.getToast()); await expect((await notification.getNotifications()).length).toBeGreaterThan(0); await notification.waitVisibility(notification.getClearNotficationsBtn()); + + // It can happen that although notifications are cleared, by the time we check the + // notifications amount, another notification can appear, so we check it more than once (if needed). await notification.waitClickableAndClick(notification.getClearNotficationsBtn()); - await notification.waitStaleness(notification.getNotifications().first()); - await expect((await notification.getNotifications()).length).toBe(0); + await notification.waitFn(async () => { + const notifications = await notification.getNotifications(); + if (notifications.length > 0) { + await notification.waitClickableAndClick(notification.getClearNotficationsBtn()); + return false; + } + return true; + }, 'Timed out checking that notifications are cleared.'); }); }); -- 2.47.3