From b25ab869f73cbce0a5b4710ba1238b054cfa0546 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 18 Jun 2018 21:05:21 -0700 Subject: [PATCH] [ftr/confirmModal] assert expected state rather than just reading (#20019) I've seen a few failures recently like https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-selenium/4940/console which are caused by the modal not being visible, but if you look at the screenshot you can see the the modal was just about to be displayed but the find didn't wait quite long enough. ~~To fix this temporarily I've increased the `isConfirmModalOpen()` timeout from 2 to 5 seconds.~~ These tests are actually trying to assert that the modal is gone, so rather than simply checking the state of the modal once, the `CommonPage#isConfirmModalOpen()` method has been renamed to `CommonPage#expectConfirmModalOpenState()` which expects a boolean and will assert the state of the confirm modal within a retry, so that as long as the modal eventually transitions to that state it will eventually resolve. ![dashboard app using legacy data dashboard listing page delete default confirm action is cancel 1](https://user-images.githubusercontent.com/1329312/41569272-3215b4aa-731f-11e8-864a-0c0022228245.png) --- .../apps/dashboard/_dashboard_listing.js | 3 +-- test/functional/apps/dashboard/_view_edit.js | 6 ++---- test/functional/page_objects/common_page.js | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/functional/apps/dashboard/_dashboard_listing.js b/test/functional/apps/dashboard/_dashboard_listing.js index 208ac30e83c7..1273b85314a5 100644 --- a/test/functional/apps/dashboard/_dashboard_listing.js +++ b/test/functional/apps/dashboard/_dashboard_listing.js @@ -67,8 +67,7 @@ export default function ({ getService, getPageObjects }) { await PageObjects.common.pressEnterKey(); - const isConfirmOpen = await PageObjects.common.isConfirmModalOpen(); - expect(isConfirmOpen).to.be(false); + await PageObjects.common.expectConfirmModalOpenState(false); const countOfDashboards = await PageObjects.dashboard.getDashboardCountWithName(dashboardName); expect(countOfDashboards).to.equal(1); diff --git a/test/functional/apps/dashboard/_view_edit.js b/test/functional/apps/dashboard/_view_edit.js index 0d1d1be7d874..f99e59323aa2 100644 --- a/test/functional/apps/dashboard/_view_edit.js +++ b/test/functional/apps/dashboard/_view_edit.js @@ -209,8 +209,7 @@ export default function ({ getService, getPageObjects }) { await PageObjects.header.setAbsoluteRange('2014-10-19 06:31:44.000', '2014-12-19 06:31:44.000'); await PageObjects.dashboard.clickCancelOutOfEditMode(); - const isOpen = await PageObjects.common.isConfirmModalOpen(); - expect(isOpen).to.be(false); + await PageObjects.common.expectConfirmModalOpenState(false); }); // See https://github.com/elastic/kibana/issues/10110 - this is intentional. @@ -222,8 +221,7 @@ export default function ({ getService, getPageObjects }) { await PageObjects.dashboard.clickCancelOutOfEditMode(); - const isOpen = await PageObjects.common.isConfirmModalOpen(); - expect(isOpen).to.be(false); + await PageObjects.common.expectConfirmModalOpenState(false); await PageObjects.dashboard.loadSavedDashboard(dashboardName); const query = await queryBar.getQueryString(); diff --git a/test/functional/page_objects/common_page.js b/test/functional/page_objects/common_page.js index 1fa5276f2244..fbf74f0453f4 100644 --- a/test/functional/page_objects/common_page.js +++ b/test/functional/page_objects/common_page.js @@ -18,6 +18,7 @@ */ import { delay } from 'bluebird'; +import expect from 'expect.js'; import getUrl from '../../../src/test_utils/get_url'; @@ -260,9 +261,20 @@ export function CommonPageProvider({ getService, getPageObjects }) { } } - async isConfirmModalOpen() { - log.debug('isConfirmModalOpen'); - return await testSubjects.exists('confirmModalCancelButton', 2000); + async expectConfirmModalOpenState(state) { + if (typeof state !== 'boolean') { + throw new Error('pass true or false to expectConfirmModalOpenState()'); + } + + log.debug(`expectConfirmModalOpenState(${state})`); + + // we use retry here instead of a simple .exists() check because the modal + // fades in/out, which takes time, and we really only care that at some point + // the modal is either open or closed + await retry.try(async () => { + const actualState = await testSubjects.exists('confirmModalCancelButton'); + expect(actualState).to.be(state); + }); } async getBreadcrumbPageTitle() {