From 5aade92c80ce3737bde7fe00cc94dda506dc3c36 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Mon, 24 Jul 2017 11:20:35 -0400 Subject: [PATCH] Make sure async functions are awaited on. --- .../apps/management/_creation_form_changes.js | 15 +++---- .../_index_pattern_create_delete.js | 11 +++-- .../apps/management/_initial_state.js | 29 ++++++------ .../functional/page_objects/dashboard_page.js | 17 +++---- test/functional/page_objects/discover_page.js | 8 ++-- test/functional/page_objects/settings_page.js | 45 ++++++++++--------- test/functional/services/doc_table.js | 4 +- 7 files changed, 62 insertions(+), 67 deletions(-) diff --git a/test/functional/apps/management/_creation_form_changes.js b/test/functional/apps/management/_creation_form_changes.js index 66bafe4bebd26..7a4ac392f0d5f 100644 --- a/test/functional/apps/management/_creation_form_changes.js +++ b/test/functional/apps/management/_creation_form_changes.js @@ -17,16 +17,13 @@ export default function ({ getService, getPageObjects }) { }); }); - it('should enable creation after selecting time field', function () { + it('should enable creation after selecting time field', async function () { // select a time field and check that Create button is enabled - return PageObjects.settings.selectTimeFieldOption('@timestamp') - .then(function () { - return PageObjects.settings.getCreateButton().isEnabled() - .then(function (enabled) { - screenshots.take('Settings-indices-enable-creation'); - expect(enabled).to.be.ok(); - }); - }); + await PageObjects.settings.selectTimeFieldOption('@timestamp'); + const createButton = await PageObjects.settings.getCreateButton(); + const enabled = await createButton.isEnabled(); + screenshots.take('Settings-indices-enable-creation'); + expect(enabled).to.be.ok(); }); }); } diff --git a/test/functional/apps/management/_index_pattern_create_delete.js b/test/functional/apps/management/_index_pattern_create_delete.js index 6ef046282ef41..726e8154a6d20 100644 --- a/test/functional/apps/management/_index_pattern_create_delete.js +++ b/test/functional/apps/management/_index_pattern_create_delete.js @@ -28,12 +28,11 @@ export default function ({ getService, getPageObjects }) { .then(id => indexPatternId = id); }); - it('should have index pattern in page header', function () { - return PageObjects.settings.getIndexPageHeading().getVisibleText() - .then(function (patternName) { - screenshots.take('Settings-indices-new-index-pattern'); - expect(patternName).to.be('logstash-*'); - }); + it('should have index pattern in page header', async function () { + const indexPageHeading = await PageObjects.settings.getIndexPageHeading(); + const patternName = await indexPageHeading.getVisibleText(); + screenshots.take('Settings-indices-new-index-pattern'); + expect(patternName).to.be('logstash-*'); }); it('should have index pattern in url', function url() { diff --git a/test/functional/apps/management/_initial_state.js b/test/functional/apps/management/_initial_state.js index 50601a33f3462..4d346b0b4f42b 100644 --- a/test/functional/apps/management/_initial_state.js +++ b/test/functional/apps/management/_initial_state.js @@ -17,28 +17,25 @@ export default function ({ getService, getPageObjects }) { }); }); - it('should contain default index pattern', function () { + it('should contain default index pattern', async function () { const defaultPattern = 'logstash-*'; - return PageObjects.settings.getIndexPatternField().getProperty('value') - .then(function (pattern) { - expect(pattern).to.be(defaultPattern); - }); + const indexPatternField = await PageObjects.settings.getIndexPatternField(); + const pattern = await indexPatternField.getProperty('value'); + expect(pattern).to.be(defaultPattern); }); - it('should not select the time field', function () { - return PageObjects.settings.getTimeFieldNameField().isSelected() - .then(function (timeFieldIsSelected) { - log.debug('timeField isSelected = ' + timeFieldIsSelected); - expect(timeFieldIsSelected).to.not.be.ok(); - }); + it('should not select the time field', async function () { + const timeFieldNameField = await PageObjects.settings.getTimeFieldNameField(); + const timeFieldIsSelected = await timeFieldNameField.isSelected(); + log.debug('timeField isSelected = ' + timeFieldIsSelected); + expect(timeFieldIsSelected).to.not.be.ok(); }); - it('should not enable creation', function () { - return PageObjects.settings.getCreateIndexPatternButton().isEnabled() - .then(function (enabled) { - expect(enabled).to.not.be.ok(); - }); + it('should not enable creation', async function () { + const createIndexPatternButton = await PageObjects.settings.getCreateIndexPatternButton(); + const enabled = await createIndexPatternButton.isEnabled(); + expect(enabled).to.not.be.ok(); }); }); } diff --git a/test/functional/page_objects/dashboard_page.js b/test/functional/page_objects/dashboard_page.js index 34250fcd057a5..a38c0f24aa461 100644 --- a/test/functional/page_objects/dashboard_page.js +++ b/test/functional/page_objects/dashboard_page.js @@ -327,18 +327,15 @@ export function DashboardPageProvider({ getService, getPageObjects }) { }); } - getPanelTitles() { + async getPanelTitles() { log.debug('in getPanelTitles'); - return testSubjects.findAll('dashboardPanelTitle') - .then(function (titleObjects) { - - function getTitles(chart) { - return chart.getVisibleText(); - } + const titleObjects = await testSubjects.findAll('dashboardPanelTitle'); - const getTitlePromises = titleObjects.map(getTitles); - return Promise.all(getTitlePromises); - }); + function getTitles(chart) { + return chart.getVisibleText(); + } + const getTitlePromises = titleObjects.map(getTitles); + return Promise.all(getTitlePromises); } async getDashboardPanels() { diff --git a/test/functional/page_objects/discover_page.js b/test/functional/page_objects/discover_page.js index a4cac1ca7a586..00cc15f9bb43a 100644 --- a/test/functional/page_objects/discover_page.js +++ b/test/functional/page_objects/discover_page.js @@ -229,8 +229,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { return await testSubjects.exists('discoverNoResults'); } - getNoResultsTimepicker() { - return testSubjects.find('discoverNoResultsTimefilter'); + async getNoResultsTimepicker() { + return await testSubjects.find('discoverNoResultsTimefilter'); } hasNoResultsTimepicker() { @@ -240,8 +240,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { .catch(() => false); } - clickFieldListItem(field) { - return testSubjects.click(`field-${field}`); + async clickFieldListItem(field) { + return await testSubjects.click(`field-${field}`); } async clickFieldListItemAdd(field) { diff --git a/test/functional/page_objects/settings_page.js b/test/functional/page_objects/settings_page.js index f479b2f16cb9d..73f3038761cd2 100644 --- a/test/functional/page_objects/settings_page.js +++ b/test/functional/page_objects/settings_page.js @@ -5,6 +5,7 @@ export function SettingsPageProvider({ getService, getPageObjects }) { const retry = getService('retry'); const config = getService('config'); const remote = getService('remote'); + const find = getService('find'); const testSubjects = getService('testSubjects'); const PageObjects = getPageObjects(['header', 'common']); @@ -61,40 +62,43 @@ export function SettingsPageProvider({ getService, getPageObjects }) { await PageObjects.common.navigateToApp('settings'); } - getIndexPatternField() { - return testSubjects.find('createIndexPatternNameInput'); + async getIndexPatternField() { + return await testSubjects.find('createIndexPatternNameInput'); } - getTimeFieldNameField() { - return testSubjects.find('createIndexPatternTimeFieldSelect'); + async clickTimeFieldNameField() { + return await testSubjects.click('createIndexPatternTimeFieldSelect'); + } + + async getTimeFieldNameField() { + return await testSubjects.find('createIndexPatternTimeFieldSelect'); } async selectTimeFieldOption(selection) { // open dropdown - (await this.getTimeFieldNameField()).click(); + await this.clickTimeFieldNameField(); // close dropdown, keep focus - (await this.getTimeFieldNameField()).click(); + await this.clickTimeFieldNameField(); await PageObjects.header.waitUntilLoadingHasFinished(); - await retry.try(async () => { + return await retry.try(async () => { log.debug(`selectTimeFieldOption(${selection})`); - (await this.getTimeFieldOption(selection)).click(); - const selected = (await this.getTimeFieldOption(selection)).isSelected(); + const timeFieldOption = await this.getTimeFieldOption(selection); + await timeFieldOption.click(); + const selected = await timeFieldOption.isSelected(); if (!selected) throw new Error('option not selected: ' + selected); }); } - getTimeFieldOption(selection) { - return remote.setFindTimeout(defaultFindTimeout) - .findDisplayedByCssSelector('option[label="' + selection + '"]'); + async getTimeFieldOption(selection) { + return await find.displayedByCssSelector('option[label="' + selection + '"]'); } - getCreateIndexPatternButton() { - return testSubjects.find('createIndexPatternCreateButton'); + async getCreateIndexPatternButton() { + return await testSubjects.find('createIndexPatternCreateButton'); } - getCreateButton() { - return remote.setFindTimeout(defaultFindTimeout) - .findDisplayedByCssSelector('[type="submit"]'); + async getCreateButton() { + return await find.displayedByCssSelector('[type="submit"]'); } async clickDefaultIndexButton() { @@ -106,8 +110,8 @@ export function SettingsPageProvider({ getService, getPageObjects }) { await testSubjects.click('deleteIndexPatternButton'); } - getIndexPageHeading() { - return testSubjects.find('indexPatternTitle'); + async getIndexPageHeading() { + return await testSubjects.find('indexPatternTitle'); } getConfigureHeader() { @@ -274,7 +278,8 @@ export function SettingsPageProvider({ getService, getPageObjects }) { await this.clickKibanaIndices(); await this.setIndexPatternField(indexPatternName); await this.selectTimeFieldOption(timefield); - await this.getCreateButton().click(); + const createButton = await this.getCreateButton(); + await createButton.click(); }); await PageObjects.header.waitUntilLoadingHasFinished(); await retry.try(async () => { diff --git a/test/functional/services/doc_table.js b/test/functional/services/doc_table.js index 98a29b22c7676..3589c3665a88e 100644 --- a/test/functional/services/doc_table.js +++ b/test/functional/services/doc_table.js @@ -2,8 +2,8 @@ export function DocTableProvider({ getService }) { const testSubjects = getService('testSubjects'); class DocTable { - getTable() { - return testSubjects.find('docTable'); + async getTable() { + return await testSubjects.find('docTable'); } async getBodyRows(table) {