From 0517362010821150ff4ab6a1b542d33596a257a6 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Tue, 25 Jul 2017 15:07:02 -0400 Subject: [PATCH] remove inline awaits (#13043) * remove inline awaits * testSubjects.find now always returns a promise, so we need to make sure there is no more inlining * more find conversions * need to pass property name * Make sure async functions are awaited on. --- test/functional/apps/dashboard/_view_edit.js | 7 +- .../apps/management/_creation_form_changes.js | 15 ++-- .../_index_pattern_create_delete.js | 11 ++- .../apps/management/_initial_state.js | 29 ++++--- test/functional/apps/status_page/index.js | 13 ++-- test/functional/page_objects/context_page.js | 23 +++--- .../functional/page_objects/dashboard_page.js | 27 +++---- test/functional/page_objects/discover_page.js | 72 +++++++---------- test/functional/page_objects/header_page.js | 8 +- .../page_objects/point_series_page.js | 5 +- test/functional/page_objects/settings_page.js | 78 +++++++++---------- test/functional/services/doc_table.js | 4 +- test/functional/services/filter_bar.js | 2 +- test/functional/services/find.js | 34 ++++++-- test/functional/services/test_subjects.js | 63 ++++++++------- 15 files changed, 189 insertions(+), 202 deletions(-) diff --git a/test/functional/apps/dashboard/_view_edit.js b/test/functional/apps/dashboard/_view_edit.js index e1881e41f3c01..81d26ccc8c2b6 100644 --- a/test/functional/apps/dashboard/_view_edit.js +++ b/test/functional/apps/dashboard/_view_edit.js @@ -152,7 +152,7 @@ export default function ({ getService, getPageObjects }) { it('when the query is edited and applied', async function () { const originalQuery = await PageObjects.dashboard.getQuery(); - await PageObjects.dashboard.appendQuery('extra stuff'); + await PageObjects.dashboard.setQuery(`${originalQuery} and extra stuff`); await PageObjects.dashboard.clickFilterButton(); await PageObjects.dashboard.clickCancelOutOfEditMode(); @@ -184,8 +184,7 @@ export default function ({ getService, getPageObjects }) { await originalFilters[0].click(); await originalFilters[0].click(); - const removeFilterButton = await testSubjects.find('removeFilter-memory'); - await removeFilterButton.click(); + await testSubjects.click('removeFilter-memory'); const noFilters = await PageObjects.dashboard.getFilters(1000); expect(noFilters.length).to.equal(0); @@ -288,7 +287,7 @@ export default function ({ getService, getPageObjects }) { await PageObjects.dashboard.gotoDashboardEditMode(dashboardName); const originalQuery = await PageObjects.dashboard.getQuery(); - await PageObjects.dashboard.appendQuery('extra stuff'); + await PageObjects.dashboard.setQuery(`${originalQuery} extra stuff`); await PageObjects.dashboard.clickCancelOutOfEditMode(); 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/apps/status_page/index.js b/test/functional/apps/status_page/index.js index be1a5ca48a857..25afb2a977ded 100644 --- a/test/functional/apps/status_page/index.js +++ b/test/functional/apps/status_page/index.js @@ -11,14 +11,11 @@ export default function ({ getService, getPageObjects }) { await PageObjects.common.navigateToApp('status_page'); }); - it('should show the kibana plugin as ready', function () { - return retry.tryForTime(6000, function () { - return testSubjects.find('statusBreakdown') - .getVisibleText() - .then(function (text) { - screenshots.take('Status'); - expect(text.indexOf('plugin:kibana')).to.be.above(-1); - }); + it('should show the kibana plugin as ready', async function () { + await retry.tryForTime(6000, async () => { + const text = await testSubjects.getVisibleText('statusBreakdown'); + screenshots.take('Status'); + expect(text.indexOf('plugin:kibana')).to.be.above(-1); }); }); }); diff --git a/test/functional/page_objects/context_page.js b/test/functional/page_objects/context_page.js index afb0762bdf12e..675e01c7cb3e5 100644 --- a/test/functional/page_objects/context_page.js +++ b/test/functional/page_objects/context_page.js @@ -28,28 +28,27 @@ export function ContextPageProvider({ getService }) { await this.waitUntilContextLoadingHasFinished(); } - getPredecessorCountPicker() { - return testSubjects.find('predecessorCountPicker'); + async getPredecessorCountPicker() { + return await testSubjects.find('predecessorCountPicker'); } - getSuccessorCountPicker() { - return testSubjects.find('successorCountPicker'); + async getSuccessorCountPicker() { + return await testSubjects.find('successorCountPicker'); } - getPredecessorLoadMoreButton() { - return testSubjects.find('predecessorLoadMoreButton'); + async getPredecessorLoadMoreButton() { + return await testSubjects.find('predecessorLoadMoreButton'); } - getSuccessorLoadMoreButton() { - return testSubjects.find('predecessorLoadMoreButton'); + async getSuccessorLoadMoreButton() { + return await testSubjects.find('predecessorLoadMoreButton'); } waitUntilContextLoadingHasFinished() { return retry.try(async () => { - if ( - !(await this.getSuccessorLoadMoreButton().isEnabled()) - || !(await this.getPredecessorLoadMoreButton().isEnabled()) - ) { + const successorLoadMoreButton = await this.getSuccessorLoadMoreButton(); + const predecessorLoadMoreButton = await this.getPredecessorLoadMoreButton(); + if (!successorLoadMoreButton.isEnabled() || !predecessorLoadMoreButton.isEnabled()) { throw new Error('loading context rows'); } }); diff --git a/test/functional/page_objects/dashboard_page.js b/test/functional/page_objects/dashboard_page.js index f8b5aef88dc9c..a38c0f24aa461 100644 --- a/test/functional/page_objects/dashboard_page.js +++ b/test/functional/page_objects/dashboard_page.js @@ -64,14 +64,14 @@ export function DashboardPageProvider({ getService, getPageObjects }) { return await queryObject.getProperty('value'); } - appendQuery(query) { - log.debug('Appending query'); - return retry.try(() => testSubjects.find('queryInput').type(query)); + async setQuery(query) { + log.debug(`setQuery(${query})`); + return await testSubjects.setValue('queryInput', query); } - clickFilterButton() { + async clickFilterButton() { log.debug('Clicking filter button'); - return testSubjects.click('querySubmitButton'); + return await testSubjects.click('querySubmitButton'); } async clickClone() { @@ -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 0d0241285cd0b..00cc15f9bb43a 100644 --- a/test/functional/page_objects/discover_page.js +++ b/test/functional/page_objects/discover_page.js @@ -3,6 +3,7 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { const log = getService('log'); const retry = getService('retry'); const testSubjects = getService('testSubjects'); + const find = getService('find'); const PageObjects = getPageObjects(['header', 'common']); const getRemote = () => ( @@ -21,9 +22,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { .findByCssSelector('button[aria-label=\'Search\']'); } - getTimespanText() { - return testSubjects.find('globalTimepickerRange') - .getVisibleText(); + async getTimespanText() { + return await testSubjects.getVisibleText('globalTimepickerRange'); } getChartTimespan() { @@ -67,9 +67,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { return testSubjects.click('discoverOpenButton'); } - getCurrentQueryName() { - return testSubjects.find('discoverCurrentQuery') - .getVisibleText(); + async getCurrentQueryName() { + return await testSubjects.getVisibleText('discoverCurrentQuery'); } getBarChartData() { @@ -126,32 +125,21 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { }); } - getChartInterval() { - return testSubjects.find('discoverIntervalSelect') - .getProperty('value') - .then(selectedValue => { - return getRemote() - .findByCssSelector('option[value="' + selectedValue + '"]') - .getVisibleText(); - }); + async getChartInterval() { + const selectedValue = await testSubjects.getProperty('discoverIntervalSelect', 'value'); + const selectedOption = await find.byCssSelector('option[value="' + selectedValue + '"]'); + return selectedOption.getVisibleText(); } - setChartInterval(interval) { - return getRemote() - .setFindTimeout(5000) - .findByCssSelector('option[label="' + interval + '"]') - .click() - .then(() => { - return PageObjects.header.waitUntilLoadingHasFinished(); - }); + async setChartInterval(interval) { + const optionElement = await find.byCssSelector('option[label="' + interval + '"]', 5000); + await optionElement.click(); + return await PageObjects.header.waitUntilLoadingHasFinished(); } - getHitCount() { - return PageObjects.header.waitUntilLoadingHasFinished() - .then(() => { - return testSubjects.find('discoverQueryHits') - .getVisibleText(); - }); + async getHitCount() { + await PageObjects.header.waitUntilLoadingHasFinished(); + return await testSubjects.getVisibleText('discoverQueryHits'); } query(queryString) { @@ -211,18 +199,16 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { return testSubjects.click('sharedSnapshotCopyButton'); } - getShareCaption() { - return testSubjects.find('shareUiTitle') - .getVisibleText(); + async getShareCaption() { + return await testSubjects.getVisibleText('shareUiTitle'); } - getSharedUrl() { - return testSubjects.find('sharedSnapshotUrl') - .getProperty('value'); + async getSharedUrl() { + return await testSubjects.getProperty('sharedSnapshotUrl', 'value'); } - toggleSidebarCollapse() { - return testSubjects.find('collapseSideBarButton').click(); + async toggleSidebarCollapse() { + return await testSubjects.click('collapseSideBarButton'); } getAllFieldNames() { @@ -239,14 +225,12 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { .getProperty('clientWidth'); } - hasNoResults() { - return testSubjects.find('discoverNoResults') - .then(() => true) - .catch(() => false); + async hasNoResults() { + return await testSubjects.exists('discoverNoResults'); } - getNoResultsTimepicker() { - return testSubjects.find('discoverNoResultsTimefilter'); + async getNoResultsTimepicker() { + return await testSubjects.find('discoverNoResultsTimefilter'); } hasNoResultsTimepicker() { @@ -256,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/header_page.js b/test/functional/page_objects/header_page.js index e83e5096259ea..6b36fa74f1a24 100644 --- a/test/functional/page_objects/header_page.js +++ b/test/functional/page_objects/header_page.js @@ -210,15 +210,11 @@ export function HeaderPageProvider({ getService, getPageObjects }) { } async getPrettyDuration() { - return await testSubjects.find('globalTimepickerRange').getVisibleText(); + return await testSubjects.getVisibleText('globalTimepickerRange'); } async isSharedTimefilterEnabled() { - const element = await remote - .setFindTimeout(defaultFindTimeout) - .findByCssSelector(`[shared-timefilter=true]`); - - return !!element; + return await find.existsByCssSelector('[shared-timefilter=true]'); } } diff --git a/test/functional/page_objects/point_series_page.js b/test/functional/page_objects/point_series_page.js index aefd682b153cc..3d0fb5cc496db 100644 --- a/test/functional/page_objects/point_series_page.js +++ b/test/functional/page_objects/point_series_page.js @@ -21,9 +21,8 @@ export function PointSeriesPageProvider({ getService }) { .click(); } - clickAddAxis() { - return testSubjects.find('visualizeAddYAxisButton') - .click(); + async clickAddAxis() { + return await testSubjects.click('visualizeAddYAxisButton'); } getValueAxesCount() { diff --git a/test/functional/page_objects/settings_page.js b/test/functional/page_objects/settings_page.js index 6f66c3d6c6890..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']); @@ -31,10 +32,9 @@ export function SettingsPageProvider({ getService, getPageObjects }) { await this.clickLinkText('Index Patterns'); } - getAdvancedSettings(propertyName) { + async getAdvancedSettings(propertyName) { log.debug('in setAdvancedSettings'); - return testSubjects.find(`advancedSetting-${propertyName}-currentValue`) - .getVisibleText(); + return await testSubjects.getVisibleText(`advancedSetting-${propertyName}-currentValue`); } async setAdvancedSettings(propertyName, propertyValue) { @@ -62,53 +62,56 @@ 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() { - await testSubjects.find('setDefaultIndexPatternButton').click(); + await testSubjects.click('setDefaultIndexPatternButton'); await PageObjects.header.waitUntilLoadingHasFinished(); } async clickDeletePattern() { - await testSubjects.find('deleteIndexPatternButton').click(); + await testSubjects.click('deleteIndexPatternButton'); } - getIndexPageHeading() { - return testSubjects.find('indexPatternTitle'); + async getIndexPageHeading() { + return await testSubjects.find('indexPatternTitle'); } getConfigureHeader() { @@ -151,14 +154,11 @@ export function SettingsPageProvider({ getService, getPageObjects }) { ); } - getFieldsTabCount() { - return retry.try(() => { - return testSubjects.find('tab-count-indexedFields') - .getVisibleText() - .then((theText) => { - // the value has () around it, remove them - return theText.replace(/\((.*)\)/, '$1'); - }); + async getFieldsTabCount() { + return await retry.try(async () => { + const text = await testSubjects.getVisibleText('tab-count-indexedFields'); + // the value has () around it, remove them + return text.replace(/\((.*)\)/, '$1'); }); } @@ -278,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 () => { @@ -305,8 +306,7 @@ export function SettingsPageProvider({ getService, getPageObjects }) { async setIndexPatternField(pattern) { log.debug(`setIndexPatternField(${pattern})`); - return testSubjects.find('createIndexPatternNameInput') - .clearValue().type(pattern); + return await testSubjects.setValue('createIndexPatternNameInput', pattern); } @@ -318,7 +318,7 @@ export function SettingsPageProvider({ getService, getPageObjects }) { }); await retry.try(async () => { log.debug('getAlertText'); - alertText = await testSubjects.find('confirmModalBodyText').getVisibleText(); + alertText = await testSubjects.getVisibleText('confirmModalBodyText'); }); await retry.try(async () => { log.debug('acceptConfirmation'); @@ -392,7 +392,7 @@ export function SettingsPageProvider({ getService, getPageObjects }) { async setScriptedFieldName(name) { log.debug('set scripted field name = ' + name); - await testSubjects.find('editorFieldName').type(name); + await testSubjects.setValue('editorFieldName', name); } async setScriptedFieldLanguage(language) { @@ -453,12 +453,12 @@ export function SettingsPageProvider({ getService, getPageObjects }) { async setScriptedFieldPopularity(popularity) { log.debug('set scripted field popularity = ' + popularity); - await testSubjects.find('editorFieldCount').type(popularity); + await testSubjects.setValue('editorFieldCount', popularity); } async setScriptedFieldScript(script) { log.debug('set scripted field script = ' + script); - await testSubjects.find('editorFieldScript').type(script); + await testSubjects.setValue('editorFieldScript', script); } } 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) { diff --git a/test/functional/services/filter_bar.js b/test/functional/services/filter_bar.js index b62f2db00cff1..1ee1c829df16a 100644 --- a/test/functional/services/filter_bar.js +++ b/test/functional/services/filter_bar.js @@ -13,7 +13,7 @@ export function FilterBarProvider({ getService }) { async toggleFilterEnabled(key) { const filterElement = await testSubjects.find(`filter & filter-key-${key}`); await remote.moveMouseTo(filterElement); - await testSubjects.find(`filter & filter-key-${key} disableFilter-${key}`).click(); + await testSubjects.click(`filter & filter-key-${key} disableFilter-${key}`); } } diff --git a/test/functional/services/find.js b/test/functional/services/find.js index 7322985d4209e..a93b4e7dd6448 100644 --- a/test/functional/services/find.js +++ b/test/functional/services/find.js @@ -6,11 +6,12 @@ export function FindProvider({ getService }) { const defaultFindTimeout = config.get('timeouts.find'); class Find { - byCssSelector(selector) { + async byCssSelector(selector, timeout = defaultFindTimeout) { log.debug(`findByCssSelector ${selector}`); - return remote - .setFindTimeout(defaultFindTimeout) - .findByCssSelector(selector); + const remoteWithTimeout = remote.setFindTimeout(timeout); + const element = await remoteWithTimeout.findByCssSelector(selector); + remoteWithTimeout.setFindTimeout(defaultFindTimeout); + return element; } async allByCssSelector(selector, timeout = defaultFindTimeout) { @@ -33,14 +34,31 @@ export function FindProvider({ getService }) { async existsByLinkText(linkText) { log.debug(`existsByLinkText ${linkText}`); + const remoteWithTimeout = remote.setFindTimeout(1000); + const exists = await remoteWithTimeout.findDisplayedByLinkText(linkText) + .then(() => true) + .catch(() => false); + remoteWithTimeout.setFindTimeout(defaultFindTimeout); + return exists; + } - const exists = await remote - .setFindTimeout(1000) - .findDisplayedByLinkText(linkText) + async existsByDisplayedByCssSelector(selector) { + log.debug(`existsByDisplayedByCssSelector ${selector}`); + const remoteWithTimeout = remote.setFindTimeout(1000); + const exists = await remoteWithTimeout.findDisplayedByCssSelector(selector) .then(() => true) .catch(() => false); + remoteWithTimeout.setFindTimeout(defaultFindTimeout); + return exists; + } - remote.setFindTimeout(defaultFindTimeout); + async existsByCssSelector(selector) { + log.debug(`existsByCssSelector ${selector}`); + const remoteWithTimeout = remote.setFindTimeout(1000); + const exists = await remoteWithTimeout.findByCssSelector(selector) + .then(() => true) + .catch(() => false); + remoteWithTimeout.setFindTimeout(defaultFindTimeout); return exists; } } diff --git a/test/functional/services/test_subjects.js b/test/functional/services/test_subjects.js index 60010345eb672..23f3ac56ac5e2 100644 --- a/test/functional/services/test_subjects.js +++ b/test/functional/services/test_subjects.js @@ -11,16 +11,16 @@ export function TestSubjectsProvider({ getService }) { class TestSubjects { async exists(selector) { - log.debug(`doesTestSubjectExist ${selector}`); - - const exists = await remote - .setFindTimeout(1000) - .findDisplayedByCssSelector(testSubjSelector(selector)) - .then(() => true) - .catch(() => false); + log.debug(`TestSubjects.exists(${selector})`); + return await find.existsByDisplayedByCssSelector(testSubjSelector(selector)); + } - remote.setFindTimeout(defaultFindTimeout); - return exists; + async append(selector, text) { + return await retry.try(async () => { + const input = await this.find(selector); + await input.click(); + await input.type(text); + }); } async click(selector) { @@ -31,33 +31,38 @@ export function TestSubjectsProvider({ getService }) { }); } - find(selector, timeout = defaultFindTimeout) { - log.debug('in findTestSubject: ' + testSubjSelector(selector)); - let originalFindTimeout = null; - return remote - .getFindTimeout() - .then((findTimeout) => originalFindTimeout = findTimeout) - .setFindTimeout(timeout) - .findDisplayedByCssSelector(testSubjSelector(selector)) - .then( - (result) => remote.setFindTimeout(originalFindTimeout) - .finally(() => result), - (error) => remote.setFindTimeout(originalFindTimeout) - .finally(() => { throw error; }), - ); + async find(selector, timeout = defaultFindTimeout) { + log.debug(`TestSubjects.find(${selector})`); + return await find.displayedByCssSelector(testSubjSelector(selector), timeout); } async findAll(selector) { - log.debug('in findAllTestSubjects: ' + testSubjSelector(selector)); + log.debug(`TestSubjects.findAll(${selector})`); const all = await find.allByCssSelector(testSubjSelector(selector)); return await filterAsync(all, el => el.isDisplayed()); } - async setValue(selector, value) { - const input = await retry.try(() => this.find(selector)); - await retry.try(() => input.click()); - await input.clearValue(); - await input.type(value); + async getProperty(selector, property) { + return await retry.try(async () => { + const element = await this.find(selector); + return await element.getProperty(property); + }); + } + + async setValue(selector, text) { + return await retry.try(async () => { + const input = await this.find(selector); + await input.click(); + await input.clearValue(); + await input.type(text); + }); + } + + async getVisibleText(selector) { + return await retry.try(async () => { + const element = await this.find(selector); + return await element.getVisibleText(); + }); } }