From 6facbb17051236dfd00d4ebf79eab07496d78e8b Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 19 Mar 2020 00:15:36 +0300 Subject: [PATCH 1/5] [web_element_wrapper] add find/findAll to search with data-test-subj --- test/functional/apps/visualize/_tile_map.js | 3 +- .../input_control_vis/input_control_range.ts | 5 +-- test/functional/page_objects/common_page.ts | 4 +-- test/functional/page_objects/discover_page.ts | 4 +-- test/functional/page_objects/newsfeed_page.ts | 2 +- test/functional/page_objects/settings_page.ts | 5 +-- test/functional/page_objects/timelion_page.js | 5 ++- .../page_objects/visual_builder_page.ts | 4 +-- .../page_objects/visualize_editor_page.ts | 2 +- test/functional/services/combo_box.ts | 11 ++---- test/functional/services/doc_table.ts | 18 +++++----- .../web_element_wrapper.ts | 34 +++++++++++++++++++ .../test/functional/page_objects/gis_page.js | 2 +- .../functional/page_objects/rollup_page.js | 30 +++++----------- .../functional/page_objects/security_page.js | 21 +++++------- .../page_objects/snapshot_restore_page.ts | 18 ++++------ .../apps/triggers_actions_ui/alerts.ts | 6 ++-- .../page_objects/triggers_actions_ui_page.ts | 4 +-- 18 files changed, 89 insertions(+), 89 deletions(-) diff --git a/test/functional/apps/visualize/_tile_map.js b/test/functional/apps/visualize/_tile_map.js index ee07e66757b6f..fb6d802803af1 100644 --- a/test/functional/apps/visualize/_tile_map.js +++ b/test/functional/apps/visualize/_tile_map.js @@ -23,7 +23,6 @@ export default function({ getService, getPageObjects }) { const log = getService('log'); const retry = getService('retry'); const inspector = getService('inspector'); - const find = getService('find'); const filterBar = getService('filterBar'); const testSubjects = getService('testSubjects'); const browser = getService('browser'); @@ -279,7 +278,7 @@ export default function({ getService, getPageObjects }) { it('should suppress zoom warning if suppress warnings button clicked', async () => { last = true; await PageObjects.visChart.waitForVisualization(); - await find.clickByCssSelector('[data-test-subj="suppressZoomWarnings"]'); + await testSubjects.find('suppressZoomWarnings'); await PageObjects.tileMap.clickMapZoomOut(waitForLoading); await testSubjects.waitForDeleted('suppressZoomWarnings'); await PageObjects.tileMap.clickMapZoomIn(waitForLoading); diff --git a/test/functional/apps/visualize/input_control_vis/input_control_range.ts b/test/functional/apps/visualize/input_control_vis/input_control_range.ts index f48ba7b54daf1..bd0dde53049cb 100644 --- a/test/functional/apps/visualize/input_control_vis/input_control_range.ts +++ b/test/functional/apps/visualize/input_control_vis/input_control_range.ts @@ -25,6 +25,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); const find = getService('find'); + const testSubjects = getService('testSubjects'); const { visualize, visEditor } = getPageObjects(['visualize', 'visEditor']); describe('input control range', () => { @@ -40,7 +41,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { await visEditor.clickGo(); await visEditor.setFilterRange(0, '7', '10'); await visEditor.inputControlSubmit(); - const controlFilters = await find.allByCssSelector('[data-test-subj^="filter"]'); + const controlFilters = await testSubjects.findAll('~filter'); expect(controlFilters).to.have.length(1); expect(await controlFilters[0].getVisibleText()).to.equal('hour_of_day: 7 to 10'); }); @@ -51,7 +52,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { await visEditor.clickGo(); await visEditor.setFilterRange(1, '400', '999'); await visEditor.inputControlSubmit(); - const controlFilters = await find.allByCssSelector('[data-test-subj^="filter"]'); + const controlFilters = await testSubjects.findAll('~filter'); expect(controlFilters).to.have.length(2); expect(await controlFilters[1].getVisibleText()).to.equal('AvgTicketPrice: $400 to $999'); }); diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts index 60966511c1f99..3745f6e8272ff 100644 --- a/test/functional/page_objects/common_page.ts +++ b/test/functional/page_objects/common_page.ts @@ -99,8 +99,8 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo */ private async loginIfPrompted(appUrl: string) { let currentUrl = await browser.getCurrentUrl(); - log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`); - await find.byCssSelector('[data-test-subj="kibanaChrome"]', 6 * defaultFindTimeout); // 60 sec waiting + log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`); // 60 sec waiting + await testSubjects.find('kibanaChrome', 6 * defaultFindTimeout); const loginPage = currentUrl.includes('/login'); const wantedLoginPage = appUrl.includes('/login') || appUrl.includes('/logout'); diff --git a/test/functional/page_objects/discover_page.ts b/test/functional/page_objects/discover_page.ts index f018a1ceda507..34bf7fee4d0a4 100644 --- a/test/functional/page_objects/discover_page.ts +++ b/test/functional/page_objects/discover_page.ts @@ -255,14 +255,14 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider public async clickFieldListPlusFilter(field: string, value: string) { // this method requires the field details to be open from clickFieldListItem() // testSubjects.find doesn't handle spaces in the data-test-subj value - await find.clickByCssSelector(`[data-test-subj="plus-${field}-${value}"]`); + await testSubjects.find(`plus-${field}-${value}`); await header.waitUntilLoadingHasFinished(); } public async clickFieldListMinusFilter(field: string, value: string) { // this method requires the field details to be open from clickFieldListItem() // testSubjects.find doesn't handle spaces in the data-test-subj value - await find.clickByCssSelector('[data-test-subj="minus-' + field + '-' + value + '"]'); + await testSubjects.find(`minus-${field}-${value}`); await header.waitUntilLoadingHasFinished(); } diff --git a/test/functional/page_objects/newsfeed_page.ts b/test/functional/page_objects/newsfeed_page.ts index 24ff21f0b47de..d6e761f3a45df 100644 --- a/test/functional/page_objects/newsfeed_page.ts +++ b/test/functional/page_objects/newsfeed_page.ts @@ -54,7 +54,7 @@ export function NewsfeedPageProvider({ getService, getPageObjects }: FtrProvider async getNewsfeedList() { const list = await testSubjects.find('NewsfeedFlyout'); - const cells = await list.findAllByCssSelector('[data-test-subj="newsHeadAlert"]'); + const cells = await list.findAll('newsHeadAlert'); const objects = []; for (const cell of cells) { diff --git a/test/functional/page_objects/settings_page.ts b/test/functional/page_objects/settings_page.ts index a0f503eb27e68..d8fa447e367f3 100644 --- a/test/functional/page_objects/settings_page.ts +++ b/test/functional/page_objects/settings_page.ts @@ -211,9 +211,10 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider } async getScriptedFieldsTabCount() { - const selector = '[data-test-subj="tab-count-scriptedFields"]'; return await retry.try(async () => { - const theText = await (await find.byCssSelector(selector)).getVisibleText(); + const theText = await ( + await testSubjects.find('tab-count-scriptedFields') + ).getVisibleText(); return theText.replace(/\((.*)\)/, '$1'); }); } diff --git a/test/functional/page_objects/timelion_page.js b/test/functional/page_objects/timelion_page.js index 4aaa654e4286a..88eda5da5ce15 100644 --- a/test/functional/page_objects/timelion_page.js +++ b/test/functional/page_objects/timelion_page.js @@ -19,7 +19,6 @@ export function TimelionPageProvider({ getService, getPageObjects }) { const testSubjects = getService('testSubjects'); - const find = getService('find'); const log = getService('log'); const PageObjects = getPageObjects(['common', 'header']); const esArchiver = getService('esArchiver'); @@ -55,12 +54,12 @@ export function TimelionPageProvider({ getService, getPageObjects }) { } async getSuggestionItemsText() { - const elements = await find.allByCssSelector('[data-test-subj="timelionSuggestionListItem"]'); + const elements = await testSubjects.findAll('timelionSuggestionListItem'); return await Promise.all(elements.map(async element => await element.getVisibleText())); } async clickSuggestion(suggestionIndex = 0, waitTime = 500) { - const elements = await find.allByCssSelector('[data-test-subj="timelionSuggestionListItem"]'); + const elements = await testSubjects.findAll('timelionSuggestionListItem'); if (suggestionIndex > elements.length) { throw new Error( `Unable to select suggestion ${suggestionIndex}, only ${elements.length} suggestions available.` diff --git a/test/functional/page_objects/visual_builder_page.ts b/test/functional/page_objects/visual_builder_page.ts index ee0cafb51d455..a30aa23fb2d79 100644 --- a/test/functional/page_objects/visual_builder_page.ts +++ b/test/functional/page_objects/visual_builder_page.ts @@ -485,7 +485,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro const labels = await testSubjects.findAll('aggRow'); const label = labels[aggNth]; - return (await label.findAllByCssSelector('[data-test-subj = "comboBoxInput"]'))[1]; + return (await label.findAll('comboBoxInput'))[1]; } public async clickColorPicker(): Promise { @@ -533,7 +533,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro */ public async getAggregationCount(nth: number = 0): Promise { const series = await this.getSeries(); - const aggregation = await series[nth].findAllByCssSelector('[data-test-subj="draggable"]'); + const aggregation = await series[nth].findAll('draggable'); return aggregation.length; } diff --git a/test/functional/page_objects/visualize_editor_page.ts b/test/functional/page_objects/visualize_editor_page.ts index cdc16babc4189..b1c3e924b3c1b 100644 --- a/test/functional/page_objects/visualize_editor_page.ts +++ b/test/functional/page_objects/visualize_editor_page.ts @@ -110,7 +110,7 @@ export function VisualizeEditorPageProvider({ getService, getPageObjects }: FtrP */ public async clickBucket(bucketName: string, type = 'buckets') { await testSubjects.click(`visEditorAdd_${type}`); - await find.clickByCssSelector(`[data-test-subj="visEditorAdd_${type}_${bucketName}"`); + await testSubjects.click(`visEditorAdd_${type}_${bucketName}`); } public async clickEnableCustomRanges() { diff --git a/test/functional/services/combo_box.ts b/test/functional/services/combo_box.ts index 33610e64f1c79..59fd7d22be6a2 100644 --- a/test/functional/services/combo_box.ts +++ b/test/functional/services/combo_box.ts @@ -218,7 +218,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont return; } - const clearBtn = await comboBox.findByCssSelector('[data-test-subj="comboBoxClearButton"]'); + const clearBtn = await comboBox.find('comboBoxClearButton'); await clearBtn.click(); const clearButtonStillExists = await this.doesClearButtonExist(comboBox); @@ -230,10 +230,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont } public async doesClearButtonExist(comboBoxElement: WebElementWrapper): Promise { - const found = await comboBoxElement.findAllByCssSelector( - '[data-test-subj="comboBoxClearButton"]', - WAIT_FOR_EXISTS_TIME - ); + const found = await comboBoxElement.findAll('comboBoxClearButton', WAIT_FOR_EXISTS_TIME); return found.length > 0; } @@ -264,9 +261,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont public async openOptionsList(comboBoxElement: WebElementWrapper): Promise { const isOptionsListOpen = await testSubjects.exists('~comboBoxOptionsList'); if (!isOptionsListOpen) { - const toggleBtn = await comboBoxElement.findByCssSelector( - '[data-test-subj="comboBoxToggleListButton"]' - ); + const toggleBtn = await comboBoxElement.findAll('comboBoxToggleListButton'); await toggleBtn.click(); } } diff --git a/test/functional/services/doc_table.ts b/test/functional/services/doc_table.ts index cb3daf20c641a..83d51e8c0b8e2 100644 --- a/test/functional/services/doc_table.ts +++ b/test/functional/services/doc_table.ts @@ -48,12 +48,12 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont public async getBodyRows(): Promise { const table = await this.getTable(); - return await table.findAllByCssSelector('[data-test-subj~="docTableRow"]'); + return await table.findAll('~docTableRow'); } public async getAnchorRow(): Promise { const table = await this.getTable(); - return await table.findByCssSelector('[data-test-subj~="docTableAnchorRow"]'); + return await table.find('~docTableAnchorRow'); } public async getRow(options: SelectOptions): Promise { @@ -73,7 +73,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont options: SelectOptions = { isAnchorRow: false, rowIndex: 0 } ): Promise { const row = await this.getRow(options); - const toggle = await row.findByCssSelector('[data-test-subj~="docTableExpandToggleColumn"]'); + const toggle = await row.find('~docTableExpandToggleColumn'); await toggle.click(); } @@ -90,7 +90,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont const detailsRow = options.isAnchorRow ? await this.getAnchorDetailsRow() : (await this.getDetailsRows())[options.rowIndex]; - return await detailsRow.findAllByCssSelector('[data-test-subj~="docTableRowAction"]'); + return await detailsRow.findAll('~docTableRowAction'); } public async getFields(options: { isAnchorRow: boolean } = { isAnchorRow: false }) { @@ -122,15 +122,13 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont detailsRow: WebElementWrapper, fieldName: WebElementWrapper ): Promise { - return await detailsRow.findByCssSelector(`[data-test-subj~="tableDocViewRow-${fieldName}"]`); + return await detailsRow.find(`~tableDocViewRow-${fieldName}`); } public async getAddInclusiveFilterButton( tableDocViewRow: WebElementWrapper ): Promise { - return await tableDocViewRow.findByCssSelector( - `[data-test-subj~="addInclusiveFilterButton"]` - ); + return await tableDocViewRow.find(`~addInclusiveFilterButton`); } public async addInclusiveFilter( @@ -146,7 +144,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont public async getAddExistsFilterButton( tableDocViewRow: WebElementWrapper ): Promise { - return await tableDocViewRow.findByCssSelector(`[data-test-subj~="addExistsFilterButton"]`); + return await tableDocViewRow.find(`~addExistsFilterButton`); } public async addExistsFilter( @@ -171,7 +169,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont const detailsRow = await row.findByXpath( './following-sibling::*[@data-test-subj="docTableDetailsRow"]' ); - return detailsRow.findByCssSelector('[data-test-subj~="docViewer"]'); + return detailsRow.find('~docViewer'); }); } } diff --git a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts index fe781c2ac02b6..2c335d03232a8 100644 --- a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts +++ b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts @@ -537,6 +537,40 @@ export class WebElementWrapper { }); } + /** + * Gets the first element inside this element matching the given data-test-subj selector. + * + * @param {string} selector + * @return {Promise} + */ + public async find(selector: string) { + return await this.retryCall(async function find(wrapper) { + return wrapper._wrap( + await wrapper._webElement.findElement(wrapper.By.css(testSubjSelector(selector))), + wrapper.By.css(selector) + ); + }); + } + + /** + * Gets all elements inside this element matching the given data-test-subj selector. + * + * @param {string} selector + * @param {number} timeout + * @return {Promise} + */ + public async findAll(selector: string, timeout?: number) { + return await this.retryCall(async function findAll(wrapper) { + return wrapper._wrapAll( + await wrapper._findWithCustomTimeout( + async () => + await wrapper._webElement.findElements(wrapper.By.css(testSubjSelector(selector))), + timeout + ) + ); + }); + } + /** * Gets the first element inside this element matching the given CSS class name. * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_WebElement.html#findElement diff --git a/x-pack/test/functional/page_objects/gis_page.js b/x-pack/test/functional/page_objects/gis_page.js index b78ec6a477e1f..3b90730db3cba 100644 --- a/x-pack/test/functional/page_objects/gis_page.js +++ b/x-pack/test/functional/page_objects/gis_page.js @@ -451,7 +451,7 @@ export function GisPageProvider({ getService, getPageObjects }) { async getCodeBlockParsedJson(dataTestSubjName) { log.debug(`Get parsed code block for ${dataTestSubjName}`); - const indexRespCodeBlock = await find.byCssSelector(`[data-test-subj="${dataTestSubjName}"]`); + const indexRespCodeBlock = await testSubjects.find(`${dataTestSubjName}`); const indexRespJson = await indexRespCodeBlock.getAttribute('innerText'); return JSON.parse(indexRespJson); } diff --git a/x-pack/test/functional/page_objects/rollup_page.js b/x-pack/test/functional/page_objects/rollup_page.js index 1514693defecb..2393f57f71f7d 100644 --- a/x-pack/test/functional/page_objects/rollup_page.js +++ b/x-pack/test/functional/page_objects/rollup_page.js @@ -111,28 +111,14 @@ export function RollupPageProvider({ getService, getPageObjects }) { async getJobList() { const jobs = await testSubjects.findAll('jobTableRow'); return mapAsync(jobs, async job => { - const jobNameElement = await job.findByCssSelector('[data-test-subj="jobTableCell-id"]'); - const jobStatusElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-status"]' - ); - const jobIndexPatternElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-indexPattern"]' - ); - const jobRollUpIndexPatternElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-rollupIndex"]' - ); - const jobDelayElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-rollupDelay"]' - ); - const jobIntervalElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-dateHistogramInterval"]' - ); - const jobGroupElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-groups"]' - ); - const jobMetricsElement = await job.findByCssSelector( - '[data-test-subj="jobTableCell-metrics"]' - ); + const jobNameElement = await job.find('jobTableCell-id'); + const jobStatusElement = await job.find('jobTableCell-status'); + const jobIndexPatternElement = await job.find('jobTableCell-indexPattern'); + const jobRollUpIndexPatternElement = await job.find('jobTableCell-rollupIndex'); + const jobDelayElement = await job.find('jobTableCell-rollupDelay'); + const jobIntervalElement = await job.find('jobTableCell-dateHistogramInterval'); + const jobGroupElement = await job.find('jobTableCell-groups'); + const jobMetricsElement = await job.find('jobTableCell-metrics'); return { jobName: await jobNameElement.getVisibleText(), diff --git a/x-pack/test/functional/page_objects/security_page.js b/x-pack/test/functional/page_objects/security_page.js index 4b097b916573d..90c3574c1b731 100644 --- a/x-pack/test/functional/page_objects/security_page.js +++ b/x-pack/test/functional/page_objects/security_page.js @@ -229,13 +229,12 @@ export function SecurityPageProvider({ getService, getPageObjects }) { async getElasticsearchUsers() { const users = await testSubjects.findAll('userRow'); return mapAsync(users, async user => { - const fullnameElement = await user.findByCssSelector('[data-test-subj="userRowFullName"]'); - const usernameElement = await user.findByCssSelector('[data-test-subj="userRowUserName"]'); - const emailElement = await user.findByCssSelector('[data-test-subj="userRowEmail"]'); - const rolesElement = await user.findByCssSelector('[data-test-subj="userRowRoles"]'); + const fullnameElement = await user.find('userRowFullName'); + const usernameElement = await user.find('userRowUserName'); + const emailElement = await user.find('userRowEmail'); + const rolesElement = await user.find('userRowRoles'); // findAllByCssSelector is substantially faster than `find.descendantExistsByCssSelector for negative cases - const isUserReserved = - (await user.findAllByCssSelector('span[data-test-subj="userReserved"]', 1)).length > 0; + const isUserReserved = (await user.findAll('userReserved', 1)).length > 0; return { username: await usernameElement.getVisibleText(), @@ -251,15 +250,11 @@ export function SecurityPageProvider({ getService, getPageObjects }) { const users = await testSubjects.findAll('roleRow'); return mapAsync(users, async role => { const [rolename, reserved, deprecated] = await Promise.all([ - role.findByCssSelector('[data-test-subj="roleRowName"]').then(el => el.getVisibleText()), + role.find('roleRowName').then(el => el.getVisibleText()), // findAllByCssSelector is substantially faster than `find.descendantExistsByCssSelector for negative cases - role - .findAllByCssSelector('span[data-test-subj="roleReserved"]', 1) - .then(el => el.length > 0), + role.findAll('roleReserved', 1).then(el => el.length > 0), // findAllByCssSelector is substantially faster than `find.descendantExistsByCssSelector for negative cases - role - .findAllByCssSelector('span[data-test-subj="roleDeprecated"]', 1) - .then(el => el.length > 0), + role.findAll('roleDeprecated', 1).then(el => el.length > 0), ]); return { diff --git a/x-pack/test/functional/page_objects/snapshot_restore_page.ts b/x-pack/test/functional/page_objects/snapshot_restore_page.ts index 1c8ba9f633111..c12c06911078d 100644 --- a/x-pack/test/functional/page_objects/snapshot_restore_page.ts +++ b/x-pack/test/functional/page_objects/snapshot_restore_page.ts @@ -28,21 +28,15 @@ export function SnapshotRestorePageProvider({ getService }: FtrProviderContext) }, async getRepoList() { const table = await testSubjects.find('repositoryTable'); - const rows = await table.findAllByCssSelector('[data-test-subj="row"]'); + const rows = await table.findAll('row'); return await Promise.all( rows.map(async row => { return { - repoName: await ( - await row.findByCssSelector('[data-test-subj="Name_cell"]') - ).getVisibleText(), - repoLink: await ( - await row.findByCssSelector('[data-test-subj="Name_cell"]') - ).findByCssSelector('a'), - repoType: await ( - await row.findByCssSelector('[data-test-subj="Type_cell"]') - ).getVisibleText(), - repoEdit: await row.findByCssSelector('[data-test-subj="editRepositoryButton"]'), - repoDelete: await row.findByCssSelector('[data-test-subj="deleteRepositoryButton"]'), + repoName: await (await row.find('Name_cell')).getVisibleText(), + repoLink: await (await row.find('Name_cell')).findByCssSelector('a'), + repoType: await (await row.find('Type_cell')).getVisibleText(), + repoEdit: await row.find('editRepositoryButton'), + repoDelete: await row.find('deleteRepositoryButton'), }; }) ); diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts index 75ae6b9ea7c21..db214075c58ea 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts @@ -84,7 +84,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { // await testSubjects.click('slackAddVariableButton'); // const variableMenuButton = await testSubjects.find('variableMenuButton-0'); // await variableMenuButton.click(); - await find.clickByCssSelector('[data-test-subj="saveAlertButton"]'); + await testSubjects.click('saveAlertButton'); const toastTitle = await pageObjects.common.closeToast(); expect(toastTitle).to.eql(`Saved '${alertName}'`); await pageObjects.triggersActionsUI.searchAlerts(alertName); @@ -274,9 +274,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await testSubjects.click('collapsedItemActions'); await testSubjects.click('deleteAlert'); - const emptyPrompt = await find.byCssSelector( - '[data-test-subj="createFirstAlertEmptyPrompt"]' - ); + const emptyPrompt = await testSubjects.find('createFirstAlertEmptyPrompt'); expect(await emptyPrompt.elementHasClass('euiEmptyPrompt')).to.be(true); }); diff --git a/x-pack/test/functional_with_es_ssl/page_objects/triggers_actions_ui_page.ts b/x-pack/test/functional_with_es_ssl/page_objects/triggers_actions_ui_page.ts index 91c7fe1f97d12..8d90d3c84b181 100644 --- a/x-pack/test/functional_with_es_ssl/page_objects/triggers_actions_ui_page.ts +++ b/x-pack/test/functional_with_es_ssl/page_objects/triggers_actions_ui_page.ts @@ -19,14 +19,14 @@ export function TriggersActionsPageProvider({ getService }: FtrProviderContext) return await testSubjects.getVisibleText('appTitle'); }, async clickCreateFirstConnectorButton() { - const createBtn = await find.byCssSelector('[data-test-subj="createFirstActionButton"]'); + const createBtn = await testSubjects.find('createFirstActionButton'); const createBtnIsVisible = await createBtn.isDisplayed(); if (createBtnIsVisible) { await createBtn.click(); } }, async clickCreateConnectorButton() { - const createBtn = await find.byCssSelector('[data-test-subj="createActionButton"]'); + const createBtn = await testSubjects.find('createActionButton'); const createBtnIsVisible = await createBtn.isDisplayed(); if (createBtnIsVisible) { await createBtn.click(); From 9af735e790c817ea180fc1e11beff3e89cb7547b Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 19 Mar 2020 00:25:33 +0300 Subject: [PATCH 2/5] fixes --- test/functional/apps/visualize/_tile_map.js | 2 +- .../apps/visualize/input_control_vis/input_control_range.ts | 5 ++--- test/functional/page_objects/discover_page.ts | 4 ++-- x-pack/test/functional/page_objects/security_page.js | 6 +++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/test/functional/apps/visualize/_tile_map.js b/test/functional/apps/visualize/_tile_map.js index fb6d802803af1..9e39e93926c95 100644 --- a/test/functional/apps/visualize/_tile_map.js +++ b/test/functional/apps/visualize/_tile_map.js @@ -278,7 +278,7 @@ export default function({ getService, getPageObjects }) { it('should suppress zoom warning if suppress warnings button clicked', async () => { last = true; await PageObjects.visChart.waitForVisualization(); - await testSubjects.find('suppressZoomWarnings'); + await testSubjects.click('suppressZoomWarnings'); await PageObjects.tileMap.clickMapZoomOut(waitForLoading); await testSubjects.waitForDeleted('suppressZoomWarnings'); await PageObjects.tileMap.clickMapZoomIn(waitForLoading); diff --git a/test/functional/apps/visualize/input_control_vis/input_control_range.ts b/test/functional/apps/visualize/input_control_vis/input_control_range.ts index bd0dde53049cb..f48ba7b54daf1 100644 --- a/test/functional/apps/visualize/input_control_vis/input_control_range.ts +++ b/test/functional/apps/visualize/input_control_vis/input_control_range.ts @@ -25,7 +25,6 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); const find = getService('find'); - const testSubjects = getService('testSubjects'); const { visualize, visEditor } = getPageObjects(['visualize', 'visEditor']); describe('input control range', () => { @@ -41,7 +40,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { await visEditor.clickGo(); await visEditor.setFilterRange(0, '7', '10'); await visEditor.inputControlSubmit(); - const controlFilters = await testSubjects.findAll('~filter'); + const controlFilters = await find.allByCssSelector('[data-test-subj^="filter"]'); expect(controlFilters).to.have.length(1); expect(await controlFilters[0].getVisibleText()).to.equal('hour_of_day: 7 to 10'); }); @@ -52,7 +51,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { await visEditor.clickGo(); await visEditor.setFilterRange(1, '400', '999'); await visEditor.inputControlSubmit(); - const controlFilters = await testSubjects.findAll('~filter'); + const controlFilters = await find.allByCssSelector('[data-test-subj^="filter"]'); expect(controlFilters).to.have.length(2); expect(await controlFilters[1].getVisibleText()).to.equal('AvgTicketPrice: $400 to $999'); }); diff --git a/test/functional/page_objects/discover_page.ts b/test/functional/page_objects/discover_page.ts index 34bf7fee4d0a4..a126cfb1bce4b 100644 --- a/test/functional/page_objects/discover_page.ts +++ b/test/functional/page_objects/discover_page.ts @@ -255,14 +255,14 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider public async clickFieldListPlusFilter(field: string, value: string) { // this method requires the field details to be open from clickFieldListItem() // testSubjects.find doesn't handle spaces in the data-test-subj value - await testSubjects.find(`plus-${field}-${value}`); + await testSubjects.click(`plus-${field}-${value}`); await header.waitUntilLoadingHasFinished(); } public async clickFieldListMinusFilter(field: string, value: string) { // this method requires the field details to be open from clickFieldListItem() // testSubjects.find doesn't handle spaces in the data-test-subj value - await testSubjects.find(`minus-${field}-${value}`); + await testSubjects.click(`minus-${field}-${value}`); await header.waitUntilLoadingHasFinished(); } diff --git a/x-pack/test/functional/page_objects/security_page.js b/x-pack/test/functional/page_objects/security_page.js index 90c3574c1b731..1886e94fc08f8 100644 --- a/x-pack/test/functional/page_objects/security_page.js +++ b/x-pack/test/functional/page_objects/security_page.js @@ -233,7 +233,7 @@ export function SecurityPageProvider({ getService, getPageObjects }) { const usernameElement = await user.find('userRowUserName'); const emailElement = await user.find('userRowEmail'); const rolesElement = await user.find('userRowRoles'); - // findAllByCssSelector is substantially faster than `find.descendantExistsByCssSelector for negative cases + // findAll is substantially faster than `find.descendantExistsByCssSelector for negative cases const isUserReserved = (await user.findAll('userReserved', 1)).length > 0; return { @@ -251,9 +251,9 @@ export function SecurityPageProvider({ getService, getPageObjects }) { return mapAsync(users, async role => { const [rolename, reserved, deprecated] = await Promise.all([ role.find('roleRowName').then(el => el.getVisibleText()), - // findAllByCssSelector is substantially faster than `find.descendantExistsByCssSelector for negative cases + // findAll is substantially faster than `find.descendantExistsByCssSelector for negative cases role.findAll('roleReserved', 1).then(el => el.length > 0), - // findAllByCssSelector is substantially faster than `find.descendantExistsByCssSelector for negative cases + // findAll is substantially faster than `find.descendantExistsByCssSelector for negative cases role.findAll('roleDeprecated', 1).then(el => el.length > 0), ]); From e97be8e36525955d4db899432b051efa80ffd88c Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 19 Mar 2020 00:29:35 +0300 Subject: [PATCH 3/5] fix wrong function call --- test/functional/services/combo_box.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/services/combo_box.ts b/test/functional/services/combo_box.ts index 59fd7d22be6a2..eb9d9b6404eab 100644 --- a/test/functional/services/combo_box.ts +++ b/test/functional/services/combo_box.ts @@ -261,7 +261,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont public async openOptionsList(comboBoxElement: WebElementWrapper): Promise { const isOptionsListOpen = await testSubjects.exists('~comboBoxOptionsList'); if (!isOptionsListOpen) { - const toggleBtn = await comboBoxElement.findAll('comboBoxToggleListButton'); + const toggleBtn = await comboBoxElement.find('comboBoxToggleListButton'); await toggleBtn.click(); } } From 40df400e4a501fb5a00a3252385ede293ad72837 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 19 Mar 2020 02:35:45 +0300 Subject: [PATCH 4/5] review fixes --- test/functional/page_objects/common_page.ts | 4 ++-- test/functional/page_objects/newsfeed_page.ts | 2 +- .../page_objects/visual_builder_page.ts | 4 ++-- test/functional/services/combo_box.ts | 9 ++++++--- test/functional/services/doc_table.ts | 16 +++++++-------- .../web_element_wrapper.ts | 4 ++-- .../functional/page_objects/rollup_page.js | 20 +++++++++++-------- .../functional/page_objects/security_page.js | 16 +++++++-------- .../page_objects/snapshot_restore_page.ts | 12 +++++------ 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts index a9979bcabb0d6..9b0f3d114d2b5 100644 --- a/test/functional/page_objects/common_page.ts +++ b/test/functional/page_objects/common_page.ts @@ -99,8 +99,8 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo */ private async loginIfPrompted(appUrl: string) { let currentUrl = await browser.getCurrentUrl(); - log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`); // 60 sec waiting - await testSubjects.find('kibanaChrome', 6 * defaultFindTimeout); + log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`); + await testSubjects.find('kibanaChrome', 6 * defaultFindTimeout); // 60 sec waiting const loginPage = currentUrl.includes('/login'); const wantedLoginPage = appUrl.includes('/login') || appUrl.includes('/logout'); diff --git a/test/functional/page_objects/newsfeed_page.ts b/test/functional/page_objects/newsfeed_page.ts index d6e761f3a45df..ade3bdadf25d4 100644 --- a/test/functional/page_objects/newsfeed_page.ts +++ b/test/functional/page_objects/newsfeed_page.ts @@ -54,7 +54,7 @@ export function NewsfeedPageProvider({ getService, getPageObjects }: FtrProvider async getNewsfeedList() { const list = await testSubjects.find('NewsfeedFlyout'); - const cells = await list.findAll('newsHeadAlert'); + const cells = await list.findAllByTestSubject('newsHeadAlert'); const objects = []; for (const cell of cells) { diff --git a/test/functional/page_objects/visual_builder_page.ts b/test/functional/page_objects/visual_builder_page.ts index a30aa23fb2d79..0bfd2141be03e 100644 --- a/test/functional/page_objects/visual_builder_page.ts +++ b/test/functional/page_objects/visual_builder_page.ts @@ -485,7 +485,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro const labels = await testSubjects.findAll('aggRow'); const label = labels[aggNth]; - return (await label.findAll('comboBoxInput'))[1]; + return (await label.findAllByTestSubject('comboBoxInput'))[1]; } public async clickColorPicker(): Promise { @@ -533,7 +533,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro */ public async getAggregationCount(nth: number = 0): Promise { const series = await this.getSeries(); - const aggregation = await series[nth].findAll('draggable'); + const aggregation = await series[nth].findAllByTestSubject('draggable'); return aggregation.length; } diff --git a/test/functional/services/combo_box.ts b/test/functional/services/combo_box.ts index eb9d9b6404eab..2c12490ccd436 100644 --- a/test/functional/services/combo_box.ts +++ b/test/functional/services/combo_box.ts @@ -218,7 +218,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont return; } - const clearBtn = await comboBox.find('comboBoxClearButton'); + const clearBtn = await comboBox.findByTestSubject('comboBoxClearButton'); await clearBtn.click(); const clearButtonStillExists = await this.doesClearButtonExist(comboBox); @@ -230,7 +230,10 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont } public async doesClearButtonExist(comboBoxElement: WebElementWrapper): Promise { - const found = await comboBoxElement.findAll('comboBoxClearButton', WAIT_FOR_EXISTS_TIME); + const found = await comboBoxElement.findAllByTestSubject( + 'comboBoxClearButton', + WAIT_FOR_EXISTS_TIME + ); return found.length > 0; } @@ -261,7 +264,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont public async openOptionsList(comboBoxElement: WebElementWrapper): Promise { const isOptionsListOpen = await testSubjects.exists('~comboBoxOptionsList'); if (!isOptionsListOpen) { - const toggleBtn = await comboBoxElement.find('comboBoxToggleListButton'); + const toggleBtn = await comboBoxElement.findByTestSubject('comboBoxToggleListButton'); await toggleBtn.click(); } } diff --git a/test/functional/services/doc_table.ts b/test/functional/services/doc_table.ts index 83d51e8c0b8e2..69650f123d99d 100644 --- a/test/functional/services/doc_table.ts +++ b/test/functional/services/doc_table.ts @@ -48,12 +48,12 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont public async getBodyRows(): Promise { const table = await this.getTable(); - return await table.findAll('~docTableRow'); + return await table.findAllByTestSubject('~docTableRow'); } public async getAnchorRow(): Promise { const table = await this.getTable(); - return await table.find('~docTableAnchorRow'); + return await table.findByTestSubject('~docTableAnchorRow'); } public async getRow(options: SelectOptions): Promise { @@ -73,7 +73,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont options: SelectOptions = { isAnchorRow: false, rowIndex: 0 } ): Promise { const row = await this.getRow(options); - const toggle = await row.find('~docTableExpandToggleColumn'); + const toggle = await row.findByTestSubject('~docTableExpandToggleColumn'); await toggle.click(); } @@ -90,7 +90,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont const detailsRow = options.isAnchorRow ? await this.getAnchorDetailsRow() : (await this.getDetailsRows())[options.rowIndex]; - return await detailsRow.findAll('~docTableRowAction'); + return await detailsRow.findAllByTestSubject('~docTableRowAction'); } public async getFields(options: { isAnchorRow: boolean } = { isAnchorRow: false }) { @@ -122,13 +122,13 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont detailsRow: WebElementWrapper, fieldName: WebElementWrapper ): Promise { - return await detailsRow.find(`~tableDocViewRow-${fieldName}`); + return await detailsRow.findByTestSubject(`~tableDocViewRow-${fieldName}`); } public async getAddInclusiveFilterButton( tableDocViewRow: WebElementWrapper ): Promise { - return await tableDocViewRow.find(`~addInclusiveFilterButton`); + return await tableDocViewRow.findByTestSubject(`~addInclusiveFilterButton`); } public async addInclusiveFilter( @@ -144,7 +144,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont public async getAddExistsFilterButton( tableDocViewRow: WebElementWrapper ): Promise { - return await tableDocViewRow.find(`~addExistsFilterButton`); + return await tableDocViewRow.findByTestSubject(`~addExistsFilterButton`); } public async addExistsFilter( @@ -169,7 +169,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont const detailsRow = await row.findByXpath( './following-sibling::*[@data-test-subj="docTableDetailsRow"]' ); - return detailsRow.find('~docViewer'); + return detailsRow.findByTestSubject('~docViewer'); }); } } diff --git a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts index 2c335d03232a8..157918df874c8 100644 --- a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts +++ b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts @@ -543,7 +543,7 @@ export class WebElementWrapper { * @param {string} selector * @return {Promise} */ - public async find(selector: string) { + public async findByTestSubject(selector: string) { return await this.retryCall(async function find(wrapper) { return wrapper._wrap( await wrapper._webElement.findElement(wrapper.By.css(testSubjSelector(selector))), @@ -559,7 +559,7 @@ export class WebElementWrapper { * @param {number} timeout * @return {Promise} */ - public async findAll(selector: string, timeout?: number) { + public async findAllByTestSubject(selector: string, timeout?: number) { return await this.retryCall(async function findAll(wrapper) { return wrapper._wrapAll( await wrapper._findWithCustomTimeout( diff --git a/x-pack/test/functional/page_objects/rollup_page.js b/x-pack/test/functional/page_objects/rollup_page.js index 2393f57f71f7d..b6bc60df6f7cd 100644 --- a/x-pack/test/functional/page_objects/rollup_page.js +++ b/x-pack/test/functional/page_objects/rollup_page.js @@ -111,14 +111,18 @@ export function RollupPageProvider({ getService, getPageObjects }) { async getJobList() { const jobs = await testSubjects.findAll('jobTableRow'); return mapAsync(jobs, async job => { - const jobNameElement = await job.find('jobTableCell-id'); - const jobStatusElement = await job.find('jobTableCell-status'); - const jobIndexPatternElement = await job.find('jobTableCell-indexPattern'); - const jobRollUpIndexPatternElement = await job.find('jobTableCell-rollupIndex'); - const jobDelayElement = await job.find('jobTableCell-rollupDelay'); - const jobIntervalElement = await job.find('jobTableCell-dateHistogramInterval'); - const jobGroupElement = await job.find('jobTableCell-groups'); - const jobMetricsElement = await job.find('jobTableCell-metrics'); + const jobNameElement = await job.findByTestSubject('jobTableCell-id'); + const jobStatusElement = await job.findByTestSubject('jobTableCell-status'); + const jobIndexPatternElement = await job.findByTestSubject('jobTableCell-indexPattern'); + const jobRollUpIndexPatternElement = await job.findByTestSubject( + 'jobTableCell-rollupIndex' + ); + const jobDelayElement = await job.findByTestSubject('jobTableCell-rollupDelay'); + const jobIntervalElement = await job.findByTestSubject( + 'jobTableCell-dateHistogramInterval' + ); + const jobGroupElement = await job.findByTestSubject('jobTableCell-groups'); + const jobMetricsElement = await job.findByTestSubject('jobTableCell-metrics'); return { jobName: await jobNameElement.getVisibleText(), diff --git a/x-pack/test/functional/page_objects/security_page.js b/x-pack/test/functional/page_objects/security_page.js index 1886e94fc08f8..b399327012a77 100644 --- a/x-pack/test/functional/page_objects/security_page.js +++ b/x-pack/test/functional/page_objects/security_page.js @@ -229,12 +229,12 @@ export function SecurityPageProvider({ getService, getPageObjects }) { async getElasticsearchUsers() { const users = await testSubjects.findAll('userRow'); return mapAsync(users, async user => { - const fullnameElement = await user.find('userRowFullName'); - const usernameElement = await user.find('userRowUserName'); - const emailElement = await user.find('userRowEmail'); - const rolesElement = await user.find('userRowRoles'); + const fullnameElement = await user.findByTestSubject('userRowFullName'); + const usernameElement = await user.findByTestSubject('userRowUserName'); + const emailElement = await user.findByTestSubject('userRowEmail'); + const rolesElement = await user.findByTestSubject('userRowRoles'); // findAll is substantially faster than `find.descendantExistsByCssSelector for negative cases - const isUserReserved = (await user.findAll('userReserved', 1)).length > 0; + const isUserReserved = (await user.findAllByTestSubject('userReserved', 1)).length > 0; return { username: await usernameElement.getVisibleText(), @@ -250,11 +250,11 @@ export function SecurityPageProvider({ getService, getPageObjects }) { const users = await testSubjects.findAll('roleRow'); return mapAsync(users, async role => { const [rolename, reserved, deprecated] = await Promise.all([ - role.find('roleRowName').then(el => el.getVisibleText()), + role.findByTestSubject('roleRowName').then(el => el.getVisibleText()), // findAll is substantially faster than `find.descendantExistsByCssSelector for negative cases - role.findAll('roleReserved', 1).then(el => el.length > 0), + role.findAllByTestSubject('roleReserved', 1).then(el => el.length > 0), // findAll is substantially faster than `find.descendantExistsByCssSelector for negative cases - role.findAll('roleDeprecated', 1).then(el => el.length > 0), + role.findAllByTestSubject('roleDeprecated', 1).then(el => el.length > 0), ]); return { diff --git a/x-pack/test/functional/page_objects/snapshot_restore_page.ts b/x-pack/test/functional/page_objects/snapshot_restore_page.ts index c12c06911078d..841345e3727f1 100644 --- a/x-pack/test/functional/page_objects/snapshot_restore_page.ts +++ b/x-pack/test/functional/page_objects/snapshot_restore_page.ts @@ -28,15 +28,15 @@ export function SnapshotRestorePageProvider({ getService }: FtrProviderContext) }, async getRepoList() { const table = await testSubjects.find('repositoryTable'); - const rows = await table.findAll('row'); + const rows = await table.findAllByTestSubject('row'); return await Promise.all( rows.map(async row => { return { - repoName: await (await row.find('Name_cell')).getVisibleText(), - repoLink: await (await row.find('Name_cell')).findByCssSelector('a'), - repoType: await (await row.find('Type_cell')).getVisibleText(), - repoEdit: await row.find('editRepositoryButton'), - repoDelete: await row.find('deleteRepositoryButton'), + repoName: await (await row.findByTestSubject('Name_cell')).getVisibleText(), + repoLink: await (await row.findByTestSubject('Name_cell')).findByCssSelector('a'), + repoType: await (await row.findByTestSubject('Type_cell')).getVisibleText(), + repoEdit: await row.findByTestSubject('editRepositoryButton'), + repoDelete: await row.findByTestSubject('deleteRepositoryButton'), }; }) ); From 33543a7ce68fb4571b1ca4fc652b1ba575e11979 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 19 Mar 2020 19:39:30 +0300 Subject: [PATCH 5/5] simplify test --- test/functional/page_objects/settings_page.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/functional/page_objects/settings_page.ts b/test/functional/page_objects/settings_page.ts index beae927090d89..15ae4ff846080 100644 --- a/test/functional/page_objects/settings_page.ts +++ b/test/functional/page_objects/settings_page.ts @@ -212,9 +212,7 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider async getScriptedFieldsTabCount() { return await retry.try(async () => { - const theText = await ( - await testSubjects.find('tab-count-scriptedFields') - ).getVisibleText(); + const theText = await testSubjects.getVisibleText('tab-count-scriptedFields'); return theText.replace(/\((.*)\)/, '$1'); }); }