From 2b344d27979009300a0fdc9e8aa18aff28a9a66a Mon Sep 17 00:00:00 2001 From: Nick Partridge Date: Wed, 10 Apr 2024 10:28:03 -0700 Subject: [PATCH] [FTR] Update `getAttribute` method return (#179715) --- .../services/test_subjects.ts | 14 ++++++++++---- .../web_element_wrapper/web_element_wrapper.ts | 11 ++++++----- test/examples/state_sync/todo_app.ts | 4 ++-- .../apps/dashboard/group3/dashboard_state.ts | 4 ++-- test/functional/apps/dashboard/group5/share.ts | 3 +-- .../common/control_group_apply_button.ts | 2 +- .../controls/common/control_group_settings.ts | 18 ++++++++++-------- .../discover/group1/_discover_histogram.ts | 9 ++++----- .../discover/group2/_data_grid_field_tokens.ts | 4 +++- .../apps/kibana_overview/_analytics.ts | 2 +- .../apps/kibana_overview/_solutions.ts | 2 +- test/functional/page_objects/console_page.ts | 12 ++++++------ test/functional/page_objects/dashboard_page.ts | 6 +++++- .../page_objects/dashboard_page_controls.ts | 11 +++++++---- test/functional/page_objects/discover_page.ts | 2 +- test/functional/page_objects/home_page.ts | 6 +++--- .../management/saved_objects_page.ts | 2 +- test/functional/page_objects/settings_page.ts | 4 ++-- test/functional/page_objects/share_page.ts | 2 +- test/functional/page_objects/tag_cloud_page.ts | 2 +- .../page_objects/unified_field_list.ts | 10 ++++++---- .../page_objects/visual_builder_page.ts | 10 +++++----- .../page_objects/visualize_chart_page.ts | 2 +- test/functional/services/combo_box.ts | 2 +- .../dashboard/panel_drilldown_actions.ts | 2 +- test/functional/services/filter_bar.ts | 4 ++-- test/functional/services/global_nav.ts | 6 ++---- test/functional/services/query_bar.ts | 2 +- test/functional/services/selectable.ts | 2 +- .../services/visualizations/elastic_chart.ts | 6 ++---- .../services/visualizations/pie_chart.ts | 2 +- .../add_cis_integration_form_page.ts | 2 +- .../page_objects/findings_page.ts | 4 +++- x-pack/test/custom_branding/tests/settings.ts | 4 ++-- .../search_examples/partial_results_example.ts | 2 +- .../drilldowns/explore_data_chart_action.ts | 2 +- .../test/functional/apps/discover/reporting.ts | 2 +- .../test/functional/page_objects/gis_page.ts | 6 +++--- .../test/functional/page_objects/graph_page.ts | 14 +++++++------- .../test/functional/page_objects/lens_page.ts | 11 +++++++---- .../functional/page_objects/reporting_page.ts | 8 ++++++++ .../search_sessions_management_page.ts | 2 +- .../page_objects/tag_management_page.ts | 7 ++++--- .../functional/page_objects/watcher_page.ts | 2 +- .../functional/services/ml/anomalies_table.ts | 2 +- .../services/ml/common_table_service.ts | 6 ++++-- .../test/functional/services/ml/common_ui.ts | 2 +- .../services/ml/job_wizard_advanced.ts | 6 +++--- .../services/ml/stack_management_jobs.ts | 2 +- .../functional/services/uptime/settings.ts | 6 +++--- .../page_objects/rule_details.ts | 2 +- .../page_objects/triggers_actions_ui_page.ts | 2 +- .../apps/observability/pages/rules_page.ts | 3 ++- .../tests/apps/discover/async_search.ts | 2 +- .../page_objects/svl_rule_details_ui_page.ts | 2 +- .../svl_triggers_actions_ui_page.ts | 2 +- .../discover/group1/_discover_histogram.ts | 9 ++++----- .../common/discover/x_pack/reporting.ts | 2 +- .../search_examples/partial_results_example.ts | 2 +- 59 files changed, 157 insertions(+), 127 deletions(-) diff --git a/packages/kbn-ftr-common-functional-ui-services/services/test_subjects.ts b/packages/kbn-ftr-common-functional-ui-services/services/test_subjects.ts index 730b7a692aabe..39cd21f284132 100644 --- a/packages/kbn-ftr-common-functional-ui-services/services/test_subjects.ts +++ b/packages/kbn-ftr-common-functional-ui-services/services/test_subjects.ts @@ -21,6 +21,10 @@ interface SetValueOptions { typeCharByChar?: boolean; } +export function nonNullable(v: T): v is NonNullable { + return v != null; +} + export class TestSubjects extends FtrService { public readonly log = this.ctx.getService('log'); public readonly retry = this.ctx.getService('retry'); @@ -226,9 +230,11 @@ export class TestSubjects extends FtrService { public async getAttributeAll(selector: string, attribute: string): Promise { this.log.debug(`TestSubjects.getAttributeAll(${selector}, ${attribute})`); - return await this._mapAll(selector, async (element: WebElementWrapper) => { - return await element.getAttribute(attribute); - }); + return ( + await this._mapAll(selector, async (element: WebElementWrapper) => { + return await element.getAttribute(attribute); + }) + ).filter(nonNullable); } public async getAttribute( @@ -240,7 +246,7 @@ export class TestSubjects extends FtrService { findTimeout?: number; tryTimeout?: number; } - ): Promise { + ): Promise { const findTimeout = (typeof options === 'number' ? options : options?.findTimeout) ?? this.config.get('timeouts.find'); diff --git a/packages/kbn-ftr-common-functional-ui-services/services/web_element_wrapper/web_element_wrapper.ts b/packages/kbn-ftr-common-functional-ui-services/services/web_element_wrapper/web_element_wrapper.ts index 568d8dc5cd879..e7083d7f17587 100644 --- a/packages/kbn-ftr-common-functional-ui-services/services/web_element_wrapper/web_element_wrapper.ts +++ b/packages/kbn-ftr-common-functional-ui-services/services/web_element_wrapper/web_element_wrapper.ts @@ -231,7 +231,7 @@ export class WebElementWrapper { * @return {Promise} */ public async elementHasClass(className: string): Promise { - const classes: string = await this._webElement.getAttribute('class'); + const classes = (await this._webElement.getAttribute('class')) ?? ''; return classes.includes(className); } @@ -262,7 +262,7 @@ export class WebElementWrapper { */ async clearValueWithKeyboard(options: TypeOptions = { charByChar: false }) { const value = await this.getAttribute('value'); - if (!value.length) { + if (!value?.length) { return; } @@ -344,10 +344,11 @@ export class WebElementWrapper { * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_WebElement.html#getAttribute * * @param {string} name + * @return {Promise} */ - public async getAttribute(name: string) { - return await this.retryCall(async function getAttribute(wrapper) { - return await wrapper._webElement.getAttribute(name); + public async getAttribute(name: string): Promise { + return await this.retryCall(async function getAttribute(wrapper): Promise { + return await wrapper._webElement.getAttribute(name); // this returns null if not found }); } diff --git a/test/examples/state_sync/todo_app.ts b/test/examples/state_sync/todo_app.ts index 68ed23c5a3eda..f4a851deba69d 100644 --- a/test/examples/state_sync/todo_app.ts +++ b/test/examples/state_sync/todo_app.ts @@ -32,7 +32,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide it('links are rendered correctly and state is preserved in links', async () => { const getHrefByLinkTestSubj = async (linkTestSubj: string) => - (await testSubjects.find(linkTestSubj)).getAttribute('href'); + (await (await testSubjects.find(linkTestSubj)).getAttribute('href')) ?? ''; await expectPathname(await getHrefByLinkTestSubj('filterLinkCompleted'), '/completed'); await expectPathname( @@ -115,7 +115,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide it('Links are rendered correctly and state is preserved in links', async () => { const getHrefByLinkTestSubj = async (linkTestSubj: string) => - (await testSubjects.find(linkTestSubj)).getAttribute('href'); + (await (await testSubjects.find(linkTestSubj)).getAttribute('href')) ?? ''; await expectHashPathname(await getHrefByLinkTestSubj('filterLinkCompleted'), '/completed'); await expectHashPathname( await getHrefByLinkTestSubj('filterLinkNotCompleted'), diff --git a/test/functional/apps/dashboard/group3/dashboard_state.ts b/test/functional/apps/dashboard/group3/dashboard_state.ts index 650d2e6b79269..e8cdc3b3aa2cb 100644 --- a/test/functional/apps/dashboard/group3/dashboard_state.ts +++ b/test/functional/apps/dashboard/group3/dashboard_state.ts @@ -295,7 +295,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('when removing a panel', async function () { await PageObjects.dashboard.waitForRenderComplete(); - const currentUrl = await getUrlFromShare(); + const currentUrl = (await getUrlFromShare()) ?? ''; const newUrl = updateAppStateQueryParam( currentUrl, (appState: Partial) => { @@ -319,7 +319,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await queryBar.clearQuery(); await dashboardAddPanel.addVisualization(PIE_CHART_VIS_NAME); await enableNewChartLibraryDebug(); - originalPieSliceStyle = await pieChart.getPieSliceStyle(`80,000`); + originalPieSliceStyle = (await pieChart.getPieSliceStyle(`80,000`)) ?? ''; }); it('updates a pie slice color on a hard refresh', async function () { diff --git a/test/functional/apps/dashboard/group5/share.ts b/test/functional/apps/dashboard/group5/share.ts index 45bb5cd80c508..298a6749e4896 100644 --- a/test/functional/apps/dashboard/group5/share.ts +++ b/test/functional/apps/dashboard/group5/share.ts @@ -52,8 +52,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { if (mode === 'savedObject') { await PageObjects.share.exportAsSavedObject(); } - const sharedUrl = await PageObjects.share.getSharedUrl(); - return sharedUrl; + return PageObjects.share.getSharedUrl(); }; describe('share dashboard', () => { diff --git a/test/functional/apps/dashboard_elements/controls/common/control_group_apply_button.ts b/test/functional/apps/dashboard_elements/controls/common/control_group_apply_button.ts index 7702202309b70..40e75ac70ff09 100644 --- a/test/functional/apps/dashboard_elements/controls/common/control_group_apply_button.ts +++ b/test/functional/apps/dashboard_elements/controls/common/control_group_apply_button.ts @@ -189,7 +189,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); describe('time slider selections', () => { - let valueBefore: string; + let valueBefore: string | null; before(async () => { valueBefore = await dashboardControls.getTimeSliceFromTimeSlider(); diff --git a/test/functional/apps/dashboard_elements/controls/common/control_group_settings.ts b/test/functional/apps/dashboard_elements/controls/common/control_group_settings.ts index f4359f9887c59..80a8bc8148977 100644 --- a/test/functional/apps/dashboard_elements/controls/common/control_group_settings.ts +++ b/test/functional/apps/dashboard_elements/controls/common/control_group_settings.ts @@ -92,14 +92,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const getRange = async () => { await dashboardControls.rangeSliderWaitForLoading(rangeSliderId); - const lower = await dashboardControls.rangeSliderGetLowerBoundAttribute( - rangeSliderId, - 'placeholder' - ); - const upper = await dashboardControls.rangeSliderGetUpperBoundAttribute( - rangeSliderId, - 'placeholder' - ); + const lower = + (await dashboardControls.rangeSliderGetLowerBoundAttribute( + rangeSliderId, + 'placeholder' + )) ?? '0'; + const upper = + (await dashboardControls.rangeSliderGetUpperBoundAttribute( + rangeSliderId, + 'placeholder' + )) ?? '0'; return parseInt(upper, 10) - parseInt(lower, 10); }; diff --git a/test/functional/apps/discover/group1/_discover_histogram.ts b/test/functional/apps/discover/group1/_discover_histogram.ts index ad5563e78f918..e695a7d97ebaa 100644 --- a/test/functional/apps/discover/group1/_discover_histogram.ts +++ b/test/functional/apps/discover/group1/_discover_histogram.ts @@ -304,10 +304,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.discover.saveSearch(savedSearch); await PageObjects.discover.chooseBreakdownField('extension.keyword'); await PageObjects.discover.setChartInterval('Second'); - let requestData = await testSubjects.getAttribute( - 'unifiedHistogramChart', - 'data-request-data' - ); + let requestData = + (await testSubjects.getAttribute('unifiedHistogramChart', 'data-request-data')) ?? ''; expect(JSON.parse(requestData)).to.eql({ dataViewId: 'long-window-logstash-*', timeField: '@timestamp', @@ -318,7 +316,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.discover.waitUntilSearchingHasFinished(); await PageObjects.discover.revertUnsavedChanges(); await PageObjects.discover.waitUntilSearchingHasFinished(); - requestData = await testSubjects.getAttribute('unifiedHistogramChart', 'data-request-data'); + requestData = + (await testSubjects.getAttribute('unifiedHistogramChart', 'data-request-data')) ?? ''; expect(JSON.parse(requestData)).to.eql({ dataViewId: 'long-window-logstash-*', timeField: '@timestamp', diff --git a/test/functional/apps/discover/group2/_data_grid_field_tokens.ts b/test/functional/apps/discover/group2/_data_grid_field_tokens.ts index 1d60fe3cd8c79..895fbee621cb1 100644 --- a/test/functional/apps/discover/group2/_data_grid_field_tokens.ts +++ b/test/functional/apps/discover/group2/_data_grid_field_tokens.ts @@ -48,7 +48,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const fieldIcons = await element.findAllByCssSelector('.kbnFieldIcon svg'); firstFieldIcons = await Promise.all( - fieldIcons.slice(0, 10).map((fieldIcon) => fieldIcon.getAttribute('aria-label')) + fieldIcons.slice(0, 10).map(async (fieldIcon) => { + return (await fieldIcon.getAttribute('aria-label')) ?? ''; + }) ).catch((error) => { log.debug(`error in findFirstFieldIcons: ${error.message}`); return undefined; diff --git a/test/functional/apps/kibana_overview/_analytics.ts b/test/functional/apps/kibana_overview/_analytics.ts index 8fd51106cd239..516f9d9e4850b 100644 --- a/test/functional/apps/kibana_overview/_analytics.ts +++ b/test/functional/apps/kibana_overview/_analytics.ts @@ -41,7 +41,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const verifyImageUrl = async (el: WebElementWrapper, imgName: string) => { const image = await el.findByCssSelector('img'); - const imageUrl = await image.getAttribute('src'); + const imageUrl = (await image.getAttribute('src')) ?? ''; expect(imageUrl.includes(imgName)).to.be(true); }; diff --git a/test/functional/apps/kibana_overview/_solutions.ts b/test/functional/apps/kibana_overview/_solutions.ts index 9869a295b6deb..75c80c0916d23 100644 --- a/test/functional/apps/kibana_overview/_solutions.ts +++ b/test/functional/apps/kibana_overview/_solutions.ts @@ -43,7 +43,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { for (let i = 0; i < solutionCards.length; i++) { const solutionCard = solutionCards[i]; const image = await solutionCard.findByCssSelector('img'); - const imageSrc = await image.getAttribute('src'); + const imageSrc = (await image.getAttribute('src')) ?? ''; const match = myRegexp.exec(imageSrc); myRegexp.lastIndex = 0; if (match && match.length > 1) { diff --git a/test/functional/page_objects/console_page.ts b/test/functional/page_objects/console_page.ts index 51e671d26301b..3fdc1e8ab0f74 100644 --- a/test/functional/page_objects/console_page.ts +++ b/test/functional/page_objects/console_page.ts @@ -147,7 +147,7 @@ export class ConsolePageObject extends FtrService { if (!element) return false; const attribute = await element.getAttribute('style'); - return !attribute.includes('display: none;'); + return !attribute?.includes('display: none;'); } public async getAutocompleteSuggestion(index: number = 0) { @@ -321,7 +321,7 @@ export class ConsolePageObject extends FtrService { await blocks[blockNumber].click(); await this.retry.waitFor('json block to be collapsed', async () => { return blocks[blockNumber].getAttribute('class').then((classes) => { - return classes.includes('ace_closed'); + return classes?.includes('ace_closed') ?? false; }); }); } @@ -336,7 +336,7 @@ export class ConsolePageObject extends FtrService { await blocks[blockNumber].click(); await this.retry.waitFor('json block to be expanded', async () => { return blocks[blockNumber].getAttribute('class').then((classes) => { - return classes.includes('ace_open'); + return classes?.includes('ace_open') ?? false; }); }); } @@ -349,7 +349,7 @@ export class ConsolePageObject extends FtrService { } const classes = await blocks[blockNumber].getAttribute('class'); - return classes.includes('ace_open'); + return classes?.includes('ace_open') ?? false; } public async selectCurrentRequest() { @@ -385,7 +385,7 @@ export class ConsolePageObject extends FtrService { }); // style attribute looks like this: "top: 0px; height: 18.5px;" height is the line height - const styleAttribute = await line.getAttribute('style'); + const styleAttribute = (await line.getAttribute('style')) ?? ''; const height = parseFloat(styleAttribute.replace(/.*height: ([+-]?\d+(\.\d+)?).*/, '$1')); const top = parseFloat(styleAttribute.replace(/.*top: ([+-]?\d+(\.\d+)?).*/, '$1')); // calculate the line number by dividing the top position by the line height @@ -490,7 +490,7 @@ export class ConsolePageObject extends FtrService { const path = []; for (const pathPart of requestPath) { const className = await pathPart.getAttribute('class'); - if (className.includes('ace_param')) { + if (className?.includes('ace_param') ?? false) { // This is a parameter, we don't want to include it in the path break; } diff --git a/test/functional/page_objects/dashboard_page.ts b/test/functional/page_objects/dashboard_page.ts index 13a3a860fe7d9..2b98eedbb62f1 100644 --- a/test/functional/page_objects/dashboard_page.ts +++ b/test/functional/page_objects/dashboard_page.ts @@ -696,7 +696,11 @@ export class DashboardPageObject extends FtrService { const attributeName = 'data-shared-items-count'; const element = await this.find.byCssSelector(`[${attributeName}]`); if (element) { - return await element.getAttribute(attributeName); + const attribute = await element.getAttribute(attributeName); + + if (!attribute) throw new Error(`no attribute found for [${attributeName}]`); + + return attribute; } throw new Error('no element'); diff --git a/test/functional/page_objects/dashboard_page_controls.ts b/test/functional/page_objects/dashboard_page_controls.ts index 119b347c2ca69..c57539ba2079b 100644 --- a/test/functional/page_objects/dashboard_page_controls.ts +++ b/test/functional/page_objects/dashboard_page_controls.ts @@ -65,7 +65,9 @@ export class DashboardPageControls extends FtrService { public async getAllControlIds() { const controlFrames = await this.testSubjects.findAll('control-frame'); const ids = await Promise.all( - controlFrames.map(async (controlFrame) => await controlFrame.getAttribute('data-control-id')) + controlFrames.map( + async (controlFrame) => (await controlFrame.getAttribute('data-control-id')) ?? '' + ) ); this.log.debug('Got all control ids:', ids); return ids; @@ -93,7 +95,7 @@ export class DashboardPageControls extends FtrService { public async clearAllControls() { const controlIds = await this.getAllControlIds(); for (const controlId of controlIds) { - await this.removeExistingControl(controlId); + if (controlId) await this.removeExistingControl(controlId); } } @@ -162,7 +164,8 @@ export class DashboardPageControls extends FtrService { false: 'NONE', }; - const switchState = await this.testSubjects.getAttribute('control-group-chaining', 'checked'); + const switchState = + (await this.testSubjects.getAttribute('control-group-chaining', 'checked')) ?? ''; if (chainingSystem !== switchStateToChainingSystem[switchState]) { await this.testSubjects.click('control-group-chaining'); } @@ -432,7 +435,7 @@ export class DashboardPageControls extends FtrService { this.log.debug(`getting available options count from options list`); await this.optionsListPopoverWaitForLoading(); const availableOptions = await this.testSubjects.find(`optionsList-control-available-options`); - return +(await availableOptions.getAttribute('data-option-count')); + return +((await availableOptions.getAttribute('data-option-count')) ?? '0'); } public async optionsListPopoverGetAvailableOptions() { diff --git a/test/functional/page_objects/discover_page.ts b/test/functional/page_objects/discover_page.ts index b7de38b825346..6704f56e5e0e1 100644 --- a/test/functional/page_objects/discover_page.ts +++ b/test/functional/page_objects/discover_page.ts @@ -356,7 +356,7 @@ export class DiscoverPageObject extends FtrService { return await cell.getVisibleText(); } else { const textContent = await cell.getAttribute('textContent'); - return textContent.trim(); + return textContent?.trim(); } }) ); diff --git a/test/functional/page_objects/home_page.ts b/test/functional/page_objects/home_page.ts index 4225f52b16994..0c85c51381b94 100644 --- a/test/functional/page_objects/home_page.ts +++ b/test/functional/page_objects/home_page.ts @@ -30,7 +30,7 @@ export class HomePageObject extends FtrService { async openSampleDataAccordion() { const accordionButton = await this.testSubjects.find('showSampleDataButton'); - let expandedAttribute = await accordionButton.getAttribute('aria-expanded'); + let expandedAttribute = (await accordionButton.getAttribute('aria-expanded')) ?? ''; let expanded = expandedAttribute.toLocaleLowerCase().includes('true'); this.log.debug(`Sample data accordion expanded: ${expanded}`); @@ -38,7 +38,7 @@ export class HomePageObject extends FtrService { await this.retry.waitFor('sample data according to be expanded', async () => { this.log.debug(`Opening sample data accordion`); await accordionButton.click(); - expandedAttribute = await accordionButton.getAttribute('aria-expanded'); + expandedAttribute = (await accordionButton.getAttribute('aria-expanded')) ?? ''; expanded = expandedAttribute.toLocaleLowerCase().includes('true'); return expanded; }); @@ -75,7 +75,7 @@ export class HomePageObject extends FtrService { const panelAttributes = await Promise.all( solutionPanels.map((panel) => panel.getAttribute('data-test-subj')) ); - return panelAttributes.map((attributeValue) => attributeValue.split('homSolutionPanel_')[1]); + return panelAttributes.map((attributeValue) => attributeValue?.split('homSolutionPanel_')[1]); } async goToSampleDataPage() { diff --git a/test/functional/page_objects/management/saved_objects_page.ts b/test/functional/page_objects/management/saved_objects_page.ts index b58907d13eabc..cbbb70587ea0e 100644 --- a/test/functional/page_objects/management/saved_objects_page.ts +++ b/test/functional/page_objects/management/saved_objects_page.ts @@ -283,7 +283,7 @@ export class SavedObjectsPageObject extends FtrService { let copySaveObjectsElement = null; const actions = await row.findByClassName('euiTableRowCell--hasActions'); // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element - const actionsHTML = await actions.getAttribute('innerHTML'); + const actionsHTML = (await actions.getAttribute('innerHTML')) ?? ''; if (actionsHTML.includes('euiCollapsedItemActionsButton')) { menuElement = await row.findByTestSubject('euiCollapsedItemActionsButton'); } diff --git a/test/functional/page_objects/settings_page.ts b/test/functional/page_objects/settings_page.ts index fc1064f1b0464..546e08fe31115 100644 --- a/test/functional/page_objects/settings_page.ts +++ b/test/functional/page_objects/settings_page.ts @@ -131,7 +131,7 @@ export class SettingsPageObject extends FtrService { } async toggleAdvancedSettingCheckbox(propertyName: string, value?: boolean) { - let curValue: string | undefined; + let curValue: string | null; if (value !== undefined) { curValue = await this.getAdvancedSettingAriaCheckbox(propertyName); @@ -669,7 +669,7 @@ export class SettingsPageObject extends FtrService { // case where we don't want the * appended so we'll remove it if it was added await field.type(indexPatternName, { charByChar: true }); const tempName = await field.getAttribute('value'); - if (tempName.length > indexPatternName.length) { + if (tempName?.length ?? 0 > indexPatternName.length) { await field.type(this.browser.keys.DELETE, { charByChar: true }); } } diff --git a/test/functional/page_objects/share_page.ts b/test/functional/page_objects/share_page.ts index ce1dc4c45e21f..f0f5fa0180f21 100644 --- a/test/functional/page_objects/share_page.ts +++ b/test/functional/page_objects/share_page.ts @@ -52,7 +52,7 @@ export class SharePageObject extends FtrService { async getSharedUrl() { await this.openPermaLinks(); - return await this.testSubjects.getAttribute('copyShareUrlButton', 'data-share-url'); + return (await this.testSubjects.getAttribute('copyShareUrlButton', 'data-share-url')) ?? ''; } async createShortUrlExistOrFail() { diff --git a/test/functional/page_objects/tag_cloud_page.ts b/test/functional/page_objects/tag_cloud_page.ts index ba7648b323ca9..56063712c6fa8 100644 --- a/test/functional/page_objects/tag_cloud_page.ts +++ b/test/functional/page_objects/tag_cloud_page.ts @@ -36,7 +36,7 @@ export class TagCloudPageObject extends FtrService { const tags = await this.find.allByCssSelector('text'); async function returnTagSize(tag: WebElementWrapper) { const style = await tag.getAttribute('style'); - const fontSize = style.match(/font-size: ([^;]*);/); + const fontSize = style?.match(/font-size: ([^;]*);/); return fontSize ? fontSize[1] : ''; } return await Promise.all(tags.map(returnTagSize)); diff --git a/test/functional/page_objects/unified_field_list.ts b/test/functional/page_objects/unified_field_list.ts index 152a1b4c1c660..d09ac99e30790 100644 --- a/test/functional/page_objects/unified_field_list.ts +++ b/test/functional/page_objects/unified_field_list.ts @@ -36,9 +36,11 @@ export class UnifiedFieldListPageObject extends FtrService { } public async getSidebarAriaDescription(): Promise { - return await ( - await this.testSubjects.find('fieldListGrouped__ariaDescription') - ).getAttribute('innerText'); + return ( + (await ( + await this.testSubjects.find('fieldListGrouped__ariaDescription') + ).getAttribute('innerText')) ?? '' + ); } public async cleanSidebarLocalStorage(): Promise { @@ -78,7 +80,7 @@ export class UnifiedFieldListPageObject extends FtrService { } return Promise.all( - elements.map(async (element) => await element.getAttribute('data-attr-field')) + elements.map(async (element) => (await element.getAttribute('data-attr-field')) ?? '') ); } diff --git a/test/functional/page_objects/visual_builder_page.ts b/test/functional/page_objects/visual_builder_page.ts index 89f1a2e9389c2..d7bb97c5c8809 100644 --- a/test/functional/page_objects/visual_builder_page.ts +++ b/test/functional/page_objects/visual_builder_page.ts @@ -373,7 +373,7 @@ export class VisualBuilderPageObject extends FtrService { return await gaugeCount.getVisibleText(); } - public async getGaugeColor(isInner = false): Promise { + public async getGaugeColor(isInner = false): Promise { await this.visChart.waitForVisualizationRenderingStabilized(); const gaugeColoredCircle = await this.testSubjects.find(`gaugeCircle${isInner ? 'Inner' : ''}`); return await gaugeColoredCircle.getAttribute('stroke'); @@ -395,7 +395,7 @@ export class VisualBuilderPageObject extends FtrService { return await gaugeCount.getVisibleText(); } - public async getTopNBarStyle(nth: number = 0): Promise { + public async getTopNBarStyle(nth: number = 0): Promise { await this.visChart.waitForVisualizationRenderingStabilized(); const topNBars = await this.testSubjects.findAll('topNInnerBar'); return await topNBars[nth].getAttribute('style'); @@ -756,19 +756,19 @@ export class VisualBuilderPageObject extends FtrService { }); } - public async getBackgroundStyle(): Promise { + public async getBackgroundStyle(): Promise { await this.visChart.waitForVisualizationRenderingStabilized(); const visualization = await this.find.byClassName('tvbVis'); return await visualization.getAttribute('style'); } - public async getMetricValueStyle(): Promise { + public async getMetricValueStyle(): Promise { await this.visChart.waitForVisualizationRenderingStabilized(); const metricValue = await this.testSubjects.find('tsvbMetricValue'); return await metricValue.getAttribute('style'); } - public async getGaugeValueStyle(): Promise { + public async getGaugeValueStyle(): Promise { await this.visChart.waitForVisualizationRenderingStabilized(); const metricValue = await this.testSubjects.find('gaugeValue'); return await metricValue.getAttribute('style'); diff --git a/test/functional/page_objects/visualize_chart_page.ts b/test/functional/page_objects/visualize_chart_page.ts index 093fcdb9edbf9..19991de54da03 100644 --- a/test/functional/page_objects/visualize_chart_page.ts +++ b/test/functional/page_objects/visualize_chart_page.ts @@ -63,7 +63,7 @@ export class VisualizeChartPageObject extends FtrService { // check if enabled but not a line, area, histogram or pie chart if (await this.find.existsByCssSelector('.visLib__chart', 1)) { const chart = await this.find.byCssSelector('.visLib__chart'); - const chartType = await chart.getAttribute('data-vislib-chart-type'); + const chartType = (await chart.getAttribute('data-vislib-chart-type')) ?? ''; if (!['line', 'area', 'histogram', 'pie'].includes(chartType)) { this.log.debug(`-- isNewLibraryChart = false`); diff --git a/test/functional/services/combo_box.ts b/test/functional/services/combo_box.ts index 69794f3d2a6c8..cb9134751ae7b 100644 --- a/test/functional/services/combo_box.ts +++ b/test/functional/services/combo_box.ts @@ -108,7 +108,7 @@ export class ComboBoxService extends FtrService { ( await this.find.allByCssSelector(`.euiFilterSelectItem`, this.WAIT_FOR_EXISTS_TIME) ).map(async (e) => { - const title = await e.getAttribute('title'); + const title = (await e.getAttribute('title')) ?? ''; return { title, formattedTitle: title.toLowerCase().trim() }; }) ) diff --git a/test/functional/services/dashboard/panel_drilldown_actions.ts b/test/functional/services/dashboard/panel_drilldown_actions.ts index 5b76ce62dd02d..57fc42f323fbe 100644 --- a/test/functional/services/dashboard/panel_drilldown_actions.ts +++ b/test/functional/services/dashboard/panel_drilldown_actions.ts @@ -62,7 +62,7 @@ export function DashboardDrilldownPanelActionsProvider({ getService }: FtrProvid async getActionHrefByText(text: string) { log.debug(`getActionHref: "${text}"`); const item = await this.getActionWebElementByText(text); - return item.getAttribute('href'); + return (await item.getAttribute('href')) ?? ''; } async openHrefByText(text: string) { diff --git a/test/functional/services/filter_bar.ts b/test/functional/services/filter_bar.ts index 5866c0ee3f18a..be4abf4e0daf2 100644 --- a/test/functional/services/filter_bar.ts +++ b/test/functional/services/filter_bar.ts @@ -175,12 +175,12 @@ export class FilterBarService extends FtrService { public async isFilterPinned(key: string): Promise { const filter = await this.testSubjects.find(`~filter & ~filter-key-${key}`); - return (await filter.getAttribute('data-test-subj')).includes('filter-pinned'); + return ((await filter.getAttribute('data-test-subj')) ?? '').includes('filter-pinned'); } public async isFilterNegated(key: string): Promise { const filter = await this.testSubjects.find(`~filter & ~filter-key-${key}`); - return (await filter.getAttribute('data-test-subj')).includes('filter-negated'); + return ((await filter.getAttribute('data-test-subj')) ?? '').includes('filter-negated'); } public async getFilterCount(): Promise { diff --git a/test/functional/services/global_nav.ts b/test/functional/services/global_nav.ts index 4bbea9c9fd7a7..bac2d76a36bbb 100644 --- a/test/functional/services/global_nav.ts +++ b/test/functional/services/global_nav.ts @@ -42,10 +42,8 @@ export class GlobalNavService extends FtrService { public async badgeExistsOrFail(expectedLabel: string): Promise { await this.testSubjects.existOrFail('headerBadge'); - const actualLabel = await this.testSubjects.getAttribute( - 'headerBadge', - 'data-test-badge-label' - ); + const actualLabel = + (await this.testSubjects.getAttribute('headerBadge', 'data-test-badge-label')) ?? ''; expect(actualLabel.toUpperCase()).to.equal(expectedLabel.toUpperCase()); } diff --git a/test/functional/services/query_bar.ts b/test/functional/services/query_bar.ts index ca6c161accc39..fa50432be10c5 100644 --- a/test/functional/services/query_bar.ts +++ b/test/functional/services/query_bar.ts @@ -18,7 +18,7 @@ export class QueryBarService extends FtrService { private readonly find = this.ctx.getService('find'); async getQueryString(): Promise { - return await this.testSubjects.getAttribute('queryInput', 'value'); + return (await this.testSubjects.getAttribute('queryInput', 'value')) ?? ''; } public async setQuery(query: string): Promise { diff --git a/test/functional/services/selectable.ts b/test/functional/services/selectable.ts index 8dd347ace74af..ce36da946afb3 100644 --- a/test/functional/services/selectable.ts +++ b/test/functional/services/selectable.ts @@ -64,7 +64,7 @@ export class SelectableService extends FtrService { const textWrapper = await option.findByClassName('euiSelectableListItem__text'); // Use innerText as getVisibleText doesn't return deeply nested text - const innerText = await textWrapper.getAttribute('innerText'); + const innerText = (await textWrapper.getAttribute('innerText')) ?? ''; // Replace screen reader and other Eui related text const visibleText = innerText diff --git a/test/functional/services/visualizations/elastic_chart.ts b/test/functional/services/visualizations/elastic_chart.ts index c3f2fdb20f388..d3ec3052cb4fa 100644 --- a/test/functional/services/visualizations/elastic_chart.ts +++ b/test/functional/services/visualizations/elastic_chart.ts @@ -124,12 +124,10 @@ export class ElasticChartService extends FtrService { */ public async getChartDebugDataFromChart(chart: WebElementWrapper): Promise { const visContainer = await chart.findByCssSelector('.echChartStatus'); - const debugDataString: string | undefined = await visContainer.getAttribute( - 'data-ech-debug-state' - ); + const debugDataString = await visContainer.getAttribute('data-ech-debug-state'); this.log.debug('data-ech-debug-state: ', debugDataString); - if (debugDataString === undefined) { + if (!debugDataString) { throw Error( `Elastic charts debugState not found, ensure 'setNewChartUiDebugFlag' is called before DOM rendering starts.` ); diff --git a/test/functional/services/visualizations/pie_chart.ts b/test/functional/services/visualizations/pie_chart.ts index 3c685222b143f..0c1254bf7a24a 100644 --- a/test/functional/services/visualizations/pie_chart.ts +++ b/test/functional/services/visualizations/pie_chart.ts @@ -126,7 +126,7 @@ export class PieChartService extends FtrService { } const pieSlices = await this.getAllPieSlices(name); const slicesStyles = await Promise.all( - pieSlices.map(async (pieSlice) => await pieSlice.getAttribute('style')) + pieSlices.map(async (pieSlice) => (await pieSlice.getAttribute('style')) ?? '') ); return slicesStyles .map( diff --git a/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts b/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts index ad8816989f133..038d16a82ca82 100644 --- a/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts +++ b/x-pack/test/cloud_security_posture_functional/page_objects/add_cis_integration_form_page.ts @@ -107,7 +107,7 @@ export function AddCisIntegrationFormPageProvider({ const integrationList = await testSubjects.findAll('agentEnrollmentFlyout'); await integrationList[0].click(); await PageObjects.header.waitUntilLoadingHasFinished(); - const fieldValue = await (await testSubjects.find(field)).getAttribute(value); + const fieldValue = (await (await testSubjects.find(field)).getAttribute(value)) ?? ''; return fieldValue; }, }; diff --git a/x-pack/test/cloud_security_posture_functional/page_objects/findings_page.ts b/x-pack/test/cloud_security_posture_functional/page_objects/findings_page.ts index f797e3503a092..bc1ae63cea51e 100644 --- a/x-pack/test/cloud_security_posture_functional/page_objects/findings_page.ts +++ b/x-pack/test/cloud_security_posture_functional/page_objects/findings_page.ts @@ -134,9 +134,11 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider async getColumnIndex(columnName: string) { const element = await this.getElement(); - const columnIndex = await ( + const columnIndexAttr = await ( await element.findByCssSelector(`[data-gridcell-column-id="${columnName}"]`) ).getAttribute('data-gridcell-column-index'); + expect(columnIndexAttr).to.not.be(null); + const columnIndex = parseInt(columnIndexAttr ?? '-1', 10); expect(columnIndex).to.be.greaterThan(-1); return columnIndex; }, diff --git a/x-pack/test/custom_branding/tests/settings.ts b/x-pack/test/custom_branding/tests/settings.ts index 234aedeb11c2a..df4ccc53e7893 100644 --- a/x-pack/test/custom_branding/tests/settings.ts +++ b/x-pack/test/custom_branding/tests/settings.ts @@ -80,7 +80,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); await goToSettings(); const img = await find.byCssSelector('img[alt="logo"]'); - const imgSrc = await img.getAttribute('src'); + const imgSrc = (await img.getAttribute('src')) ?? ''; expect(imgSrc.startsWith('data:image/png')).to.be(true); }); @@ -93,7 +93,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await goToSettings(); const logo = await testSubjects.find('logo'); const img = await logo.findByCssSelector('.chrHeaderLogo__mark'); - const imgSrc = await img.getAttribute('src'); + const imgSrc = (await img.getAttribute('src')) ?? ''; expect(imgSrc.startsWith('data:image/png')).to.be(true); }); }); diff --git a/x-pack/test/examples/search_examples/partial_results_example.ts b/x-pack/test/examples/search_examples/partial_results_example.ts index 269b2e79ab38f..4548ab7c191dc 100644 --- a/x-pack/test/examples/search_examples/partial_results_example.ts +++ b/x-pack/test/examples/search_examples/partial_results_example.ts @@ -30,7 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await testSubjects.click('requestFibonacci'); await retry.waitFor('update progress bar', async () => { - const newValue = await progressBar.getAttribute('value'); + const newValue = (await progressBar.getAttribute('value')) ?? ''; return parseFloat(newValue) > 0; }); }); diff --git a/x-pack/test/functional/apps/dashboard/group3/drilldowns/explore_data_chart_action.ts b/x-pack/test/functional/apps/dashboard/group3/drilldowns/explore_data_chart_action.ts index b8521914da174..7491acc447979 100644 --- a/x-pack/test/functional/apps/dashboard/group3/drilldowns/explore_data_chart_action.ts +++ b/x-pack/test/functional/apps/dashboard/group3/drilldowns/explore_data_chart_action.ts @@ -39,7 +39,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('action is a link element', async () => { const actionElement = await testSubjects.find(ACTION_TEST_SUBJ); const tag = await actionElement.getTagName(); - const href = await actionElement.getAttribute('href'); + const href = (await actionElement.getAttribute('href')) ?? ''; expect(tag.toLowerCase()).to.be('a'); expect(typeof href).to.be('string'); diff --git a/x-pack/test/functional/apps/discover/reporting.ts b/x-pack/test/functional/apps/discover/reporting.ts index 78166fd85d22e..50c1a7f860072 100644 --- a/x-pack/test/functional/apps/discover/reporting.ts +++ b/x-pack/test/functional/apps/discover/reporting.ts @@ -125,7 +125,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await browser.getActions().keyDown(Key.CONTROL).perform(); await browser.getActions().keyDown('v').perform(); - const reportURL = decodeURIComponent(await textInput.getAttribute('value')); + const reportURL = decodeURIComponent((await textInput.getAttribute('value')) ?? ''); // get number of filters in URLs const timeFiltersNumberInReportURL = diff --git a/x-pack/test/functional/page_objects/gis_page.ts b/x-pack/test/functional/page_objects/gis_page.ts index 2c779555d6227..5d0fd7cd14947 100644 --- a/x-pack/test/functional/page_objects/gis_page.ts +++ b/x-pack/test/functional/page_objects/gis_page.ts @@ -310,9 +310,9 @@ export class GisPageObject extends FtrService { await this.setViewPopoverToggle.close(); return { - lat: parseFloat(lat), - lon: parseFloat(lon), - zoom: parseFloat(zoom), + lat: parseFloat(lat ?? ''), + lon: parseFloat(lon ?? ''), + zoom: parseFloat(zoom ?? ''), }; } diff --git a/x-pack/test/functional/page_objects/graph_page.ts b/x-pack/test/functional/page_objects/graph_page.ts index 810048a7f144f..c4e2c8010c31b 100644 --- a/x-pack/test/functional/page_objects/graph_page.ts +++ b/x-pack/test/functional/page_objects/graph_page.ts @@ -76,16 +76,16 @@ export class GraphPageObject extends FtrService { } private async getCirclePosition(element: WebElementWrapper) { - const x = await element.getAttribute('cx'); - const y = await element.getAttribute('cy'); + const x = (await element.getAttribute('cx')) ?? ''; + const y = (await element.getAttribute('cy')) ?? ''; return this.getPositionAsString(x, y); } private async getLinePositions(element: WebElementWrapper) { - const x1 = await element.getAttribute('x1'); - const y1 = await element.getAttribute('y1'); - const x2 = await element.getAttribute('x2'); - const y2 = await element.getAttribute('y2'); + const x1 = (await element.getAttribute('x1')) ?? ''; + const y1 = (await element.getAttribute('y1')) ?? ''; + const x2 = (await element.getAttribute('x2')) ?? ''; + const y2 = (await element.getAttribute('y2')) ?? ''; return [this.getPositionAsString(x1, y1), this.getPositionAsString(x2, y2)]; } @@ -154,7 +154,7 @@ export class GraphPageObject extends FtrService { const tagName: string = await element.getTagName(); if (tagName === 'line') { const [sourcePosition, targetPosition] = await this.getLinePositions(element); - const lineStyle = await element.getAttribute('style'); + const lineStyle = (await element.getAttribute('style')) ?? ''; // grep out the width of the connection from the style attribute const strokeWidth = Number(/stroke-width: ?(\d+(\.\d+)?)/.exec(lineStyle)![1]); edges.push({ diff --git a/x-pack/test/functional/page_objects/lens_page.ts b/x-pack/test/functional/page_objects/lens_page.ts index c82ac1a72ec81..af877fb24e07b 100644 --- a/x-pack/test/functional/page_objects/lens_page.ts +++ b/x-pack/test/functional/page_objects/lens_page.ts @@ -1126,7 +1126,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont async getDatatableCellStyle(rowIndex = 0, colIndex = 0) { const el = await this.getDatatableCell(rowIndex, colIndex); - const styleString = await el.getAttribute('style'); + const styleString = (await el.getAttribute('style')) ?? ''; return styleString.split(';').reduce>((memo, cssLine) => { const [prop, value] = cssLine.split(':'); if (prop && value) { @@ -1138,7 +1138,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont async getDatatableCellSpanStyle(rowIndex = 0, colIndex = 0) { const el = await (await this.getDatatableCell(rowIndex, colIndex)).findByCssSelector('span'); - const styleString = await el.getAttribute('style'); + const styleString = (await el.getAttribute('style')) ?? ''; return styleString.split(';').reduce>((memo, cssLine) => { const [prop, value] = cssLine.split(':'); if (prop && value) { @@ -1317,7 +1317,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont async getLegacyMetricStyle() { const el = await testSubjects.find('metric_value'); - const styleString = await el.getAttribute('style'); + const styleString = (await el.getAttribute('style')) ?? ''; return styleString.split(';').reduce>((memo, cssLine) => { const [prop, value] = cssLine.split(':'); if (prop && value) { @@ -1792,7 +1792,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont return Promise.all( allFieldsForType.map(async (el) => { const parent = await el.findByXpath('./..'); - return parent.getAttribute('data-test-subj'); + return (await parent.getAttribute('data-test-subj')) ?? ''; }) ); }, @@ -1857,6 +1857,9 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont await testSubjects.click(testSubFrom); const copyButton = await testSubjects.find('copyShareUrlButton'); const url = await copyButton.getAttribute('data-share-url'); + if (!url) { + throw Error('No data-share-url attribute found'); + } return url; }, diff --git a/x-pack/test/functional/page_objects/reporting_page.ts b/x-pack/test/functional/page_objects/reporting_page.ts index 789421f1985d1..052d1898e4485 100644 --- a/x-pack/test/functional/page_objects/reporting_page.ts +++ b/x-pack/test/functional/page_objects/reporting_page.ts @@ -46,6 +46,14 @@ export class ReportingPageObject extends FtrService { 'href', timeout ); + if (!url) { + throw new Error( + `${ + url === null ? 'No' : 'Empty' + } href found on [data-test-subj="downloadCompletedReportButton"]` + ); + } + this.log.debug(`getReportURL got url: ${url}`); return url; diff --git a/x-pack/test/functional/page_objects/search_sessions_management_page.ts b/x-pack/test/functional/page_objects/search_sessions_management_page.ts index 968a88e3cad6f..6d704387e21f2 100644 --- a/x-pack/test/functional/page_objects/search_sessions_management_page.ts +++ b/x-pack/test/functional/page_objects/search_sessions_management_page.ts @@ -34,7 +34,7 @@ export function SearchSessionsPageProvider({ getService, getPageObjects }: FtrPr const actionsCell = await row.findByTestSubject('sessionManagementActionsCol'); return { - id: (await row.getAttribute('data-test-search-session-id')).split('id-')[1], + id: ((await row.getAttribute('data-test-search-session-id')) ?? '').split('id-')[1], name: $.findTestSubject('sessionManagementNameCol').text().trim(), status: $.findTestSubject('sessionManagementStatusLabel').attr('data-test-status'), mainUrl: $.findTestSubject('sessionManagementNameCol').text(), diff --git a/x-pack/test/functional/page_objects/tag_management_page.ts b/x-pack/test/functional/page_objects/tag_management_page.ts index 4684ad3e6a70e..68100ef3ad6db 100644 --- a/x-pack/test/functional/page_objects/tag_management_page.ts +++ b/x-pack/test/functional/page_objects/tag_management_page.ts @@ -95,9 +95,10 @@ class TagModal extends FtrService { */ async getFormValues(): Promise> { return { - name: await this.testSubjects.getAttribute('createModalField-name', 'value'), - color: await this.testSubjects.getAttribute('~createModalField-color', 'value'), - description: await this.testSubjects.getAttribute('createModalField-description', 'value'), + name: (await this.testSubjects.getAttribute('createModalField-name', 'value')) ?? '', + color: (await this.testSubjects.getAttribute('~createModalField-color', 'value')) ?? '', + description: + (await this.testSubjects.getAttribute('createModalField-description', 'value')) ?? '', }; } diff --git a/x-pack/test/functional/page_objects/watcher_page.ts b/x-pack/test/functional/page_objects/watcher_page.ts index ad5153a933466..8eb50ffe203e3 100644 --- a/x-pack/test/functional/page_objects/watcher_page.ts +++ b/x-pack/test/functional/page_objects/watcher_page.ts @@ -57,7 +57,7 @@ export class WatcherPageObject extends FtrService { const name = await watch.findByCssSelector('td:nth-child(3)'); return { - checkBox: (await checkBox.getAttribute('innerHTML')).includes('input'), + checkBox: ((await checkBox.getAttribute('innerHTML')) ?? '').includes('input'), id: await id.getVisibleText(), name: (await name.getVisibleText()).split(',').map((role) => role.trim()), }; diff --git a/x-pack/test/functional/services/ml/anomalies_table.ts b/x-pack/test/functional/services/ml/anomalies_table.ts index c59221289f848..35a53d90f6b9c 100644 --- a/x-pack/test/functional/services/ml/anomalies_table.ts +++ b/x-pack/test/functional/services/ml/anomalies_table.ts @@ -219,7 +219,7 @@ export function MachineLearningAnomaliesTableProvider({ getService }: FtrProvide }, async scrollRowIntoView(rowIndex: number) { - const rowSubj = await this.getRowSubjByRowIndex(rowIndex); + const rowSubj = (await this.getRowSubjByRowIndex(rowIndex)) ?? ''; await testSubjects.scrollIntoView(rowSubj); }, }; diff --git a/x-pack/test/functional/services/ml/common_table_service.ts b/x-pack/test/functional/services/ml/common_table_service.ts index a6435ab4b668d..3e8227323d763 100644 --- a/x-pack/test/functional/services/ml/common_table_service.ts +++ b/x-pack/test/functional/services/ml/common_table_service.ts @@ -128,8 +128,10 @@ export function MlTableServiceProvider({ getPageObject, getService }: FtrProvide const headers = await table.findAllByClassName('euiTableHeaderCell'); for (const header of headers) { const ariaSort = await header.getAttribute('aria-sort'); - if (ariaSort !== 'none') { - const columnNameFragments = (await header.getAttribute('data-test-subj')).split('_'); + if (ariaSort && ariaSort !== 'none') { + const columnNameFragments = ((await header.getAttribute('data-test-subj')) ?? '').split( + '_' + ); const columnName = columnNameFragments.slice(1, columnNameFragments.length - 1).join('_'); return { columnName, direction: ariaSort.replace('ending', '') }; } diff --git a/x-pack/test/functional/services/ml/common_ui.ts b/x-pack/test/functional/services/ml/common_ui.ts index 98404c88b412e..9183cf42ab041 100644 --- a/x-pack/test/functional/services/ml/common_ui.ts +++ b/x-pack/test/functional/services/ml/common_ui.ts @@ -216,7 +216,7 @@ export function MachineLearningCommonUIProvider({ const slider = await testSubjects.find(testDataSubj); await retry.tryForTime(60 * 1000, async () => { - const currentValue = await slider.getAttribute('value'); + const currentValue = (await slider.getAttribute('value')) ?? ''; const currentDiff = +currentValue - +value; if (currentDiff === 0) { diff --git a/x-pack/test/functional/services/ml/job_wizard_advanced.ts b/x-pack/test/functional/services/ml/job_wizard_advanced.ts index 8679a61be31f1..317001efd75f8 100644 --- a/x-pack/test/functional/services/ml/job_wizard_advanced.ts +++ b/x-pack/test/functional/services/ml/job_wizard_advanced.ts @@ -22,10 +22,10 @@ export function MachineLearningJobWizardAdvancedProvider( return { async getValueOrPlaceholder(inputLocator: string): Promise { const value = await testSubjects.getAttribute(inputLocator, 'value'); - if (value !== '') { - return value; + if (!value) { + return (await testSubjects.getAttribute(inputLocator, 'placeholder')) ?? ''; } else { - return await testSubjects.getAttribute(inputLocator, 'placeholder'); + return value; } }, diff --git a/x-pack/test/functional/services/ml/stack_management_jobs.ts b/x-pack/test/functional/services/ml/stack_management_jobs.ts index b67e90f126a61..63c2005650c0d 100644 --- a/x-pack/test/functional/services/ml/stack_management_jobs.ts +++ b/x-pack/test/functional/services/ml/stack_management_jobs.ts @@ -477,7 +477,7 @@ export function MachineLearningStackManagementJobsProvider({ ).findAllByClassName('euiAvatar--space'); for (const el of spacesEl) { - spaces.push((await el.getAttribute('data-test-subj')).replace('space-avatar-', '')); + spaces.push(((await el.getAttribute('data-test-subj')) ?? '').replace('space-avatar-', '')); } return spaces; diff --git a/x-pack/test/functional/services/uptime/settings.ts b/x-pack/test/functional/services/uptime/settings.ts index e51560c813d44..84a94cd6f7243 100644 --- a/x-pack/test/functional/services/uptime/settings.ts +++ b/x-pack/test/functional/services/uptime/settings.ts @@ -36,9 +36,9 @@ export function UptimeSettingsProvider({ getService }: FtrProviderContext) { const indInput = await testSubjects.find('heartbeat-indices-input-loaded', 5000); const expirationInput = await testSubjects.find('expiration-threshold-input-loaded', 5000); const ageInput = await testSubjects.find('age-threshold-input-loaded', 5000); - const heartbeatIndices = await indInput.getAttribute('value'); - const expiration = await expirationInput.getAttribute('value'); - const age = await ageInput.getAttribute('value'); + const heartbeatIndices = (await indInput.getAttribute('value')) ?? '0'; + const expiration = (await expirationInput.getAttribute('value')) ?? '0'; + const age = (await ageInput.getAttribute('value')) ?? '0'; return { heartbeatIndices, diff --git a/x-pack/test/functional_with_es_ssl/page_objects/rule_details.ts b/x-pack/test/functional_with_es_ssl/page_objects/rule_details.ts index 008679c726ef5..4bd4f862e7d7f 100644 --- a/x-pack/test/functional_with_es_ssl/page_objects/rule_details.ts +++ b/x-pack/test/functional_with_es_ssl/page_objects/rule_details.ts @@ -56,7 +56,7 @@ export function RuleDetailsPageProvider({ getService }: FtrProviderContext) { const alertDurationEpoch = await find.byCssSelector( 'input[data-test-subj="alertsDurationEpoch"]' ); - return parseInt(await alertDurationEpoch.getAttribute('value'), 10); + return parseInt((await alertDurationEpoch.getAttribute('value')) ?? '0', 10); }, async clickAlertMuteButton(alert: string) { const muteAlertButton = await testSubjects.find(`muteAlertButton_${alert}`); 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 c03728311b2a6..77c6b9b692678 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 @@ -201,7 +201,7 @@ export function TriggersActionsPageProvider({ getService }: FtrProviderContext) await retry.tryForTime(30000, async () => { await this.searchAlerts(ruleName); const statusControl = await testSubjects.find(controlName); - const title = await statusControl.getAttribute('title'); + const title = (await statusControl.getAttribute('title')) ?? ''; expect(title.toLowerCase()).to.eql(expectedStatus.toLowerCase()); }); }, diff --git a/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts b/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts index ca202b2a9e28d..765fb2e6cdcbf 100644 --- a/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts +++ b/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts @@ -114,7 +114,8 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => { describe('Feature flag', () => { it('Link point to O11y Rules pages by default', async () => { - const manageRulesPageHref = await observability.alerts.rulesPage.getManageRulesPageHref(); + const manageRulesPageHref = + (await observability.alerts.rulesPage.getManageRulesPageHref()) ?? ''; expect(new URL(manageRulesPageHref).pathname).equal('/app/observability/alerts/rules'); }); }); diff --git a/x-pack/test/search_sessions_integration/tests/apps/discover/async_search.ts b/x-pack/test/search_sessions_integration/tests/apps/discover/async_search.ts index 3f586ddc89856..ae1004db12cf3 100644 --- a/x-pack/test/search_sessions_integration/tests/apps/discover/async_search.ts +++ b/x-pack/test/search_sessions_integration/tests/apps/discover/async_search.ts @@ -157,6 +157,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.find('inspectorRequestSearchSessionId') ).getAttribute('data-search-session-id'); await inspector.close(); - return searchSessionId; + return searchSessionId ?? ''; } } diff --git a/x-pack/test_serverless/functional/page_objects/svl_rule_details_ui_page.ts b/x-pack/test_serverless/functional/page_objects/svl_rule_details_ui_page.ts index bd6ae5e0ce971..4f0e1cbe723a6 100644 --- a/x-pack/test_serverless/functional/page_objects/svl_rule_details_ui_page.ts +++ b/x-pack/test_serverless/functional/page_objects/svl_rule_details_ui_page.ts @@ -56,7 +56,7 @@ export function SvlRuleDetailsPageProvider({ getService }: FtrProviderContext) { const alertDurationEpoch = await find.byCssSelector( 'input[data-test-subj="alertsDurationEpoch"]' ); - return parseInt(await alertDurationEpoch.getAttribute('value'), 10); + return parseInt((await alertDurationEpoch.getAttribute('value')) ?? '', 10); }, async clickAlertMuteButton(alert: string) { const muteAlertButton = await testSubjects.find(`muteAlertButton_${alert}`); diff --git a/x-pack/test_serverless/functional/page_objects/svl_triggers_actions_ui_page.ts b/x-pack/test_serverless/functional/page_objects/svl_triggers_actions_ui_page.ts index e9f407c06753f..c084e3eda6a7b 100644 --- a/x-pack/test_serverless/functional/page_objects/svl_triggers_actions_ui_page.ts +++ b/x-pack/test_serverless/functional/page_objects/svl_triggers_actions_ui_page.ts @@ -202,7 +202,7 @@ export function SvlTriggersActionsPageProvider({ getService }: FtrProviderContex await this.searchRules(ruleName); const statusControl = await testSubjects.find(controlName); const title = await statusControl.getAttribute('title'); - expect(title.toLowerCase()).to.eql(expectedStatus.toLowerCase()); + expect(title?.toLowerCase()).to.eql(expectedStatus.toLowerCase()); }); }, async ensureEventLogColumnExists(columnId: string) { diff --git a/x-pack/test_serverless/functional/test_suites/common/discover/group1/_discover_histogram.ts b/x-pack/test_serverless/functional/test_suites/common/discover/group1/_discover_histogram.ts index 127621ce9d0bf..eb45495bf2522 100644 --- a/x-pack/test_serverless/functional/test_suites/common/discover/group1/_discover_histogram.ts +++ b/x-pack/test_serverless/functional/test_suites/common/discover/group1/_discover_histogram.ts @@ -308,10 +308,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.discover.saveSearch(savedSearch); await PageObjects.discover.chooseBreakdownField('extension.keyword'); await PageObjects.discover.setChartInterval('Second'); - let requestData = await testSubjects.getAttribute( - 'unifiedHistogramChart', - 'data-request-data' - ); + let requestData = + (await testSubjects.getAttribute('unifiedHistogramChart', 'data-request-data')) ?? ''; expect(JSON.parse(requestData)).to.eql({ dataViewId: 'long-window-logstash-*', timeField: '@timestamp', @@ -322,7 +320,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.discover.waitUntilSearchingHasFinished(); await PageObjects.discover.revertUnsavedChanges(); await PageObjects.discover.waitUntilSearchingHasFinished(); - requestData = await testSubjects.getAttribute('unifiedHistogramChart', 'data-request-data'); + requestData = + (await testSubjects.getAttribute('unifiedHistogramChart', 'data-request-data')) ?? ''; expect(JSON.parse(requestData)).to.eql({ dataViewId: 'long-window-logstash-*', timeField: '@timestamp', diff --git a/x-pack/test_serverless/functional/test_suites/common/discover/x_pack/reporting.ts b/x-pack/test_serverless/functional/test_suites/common/discover/x_pack/reporting.ts index e7e32c3c94dde..c07899a664ba4 100644 --- a/x-pack/test_serverless/functional/test_suites/common/discover/x_pack/reporting.ts +++ b/x-pack/test_serverless/functional/test_suites/common/discover/x_pack/reporting.ts @@ -139,7 +139,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { .perform(); await browser.getActions().keyDown('v').perform(); - const reportURL = decodeURIComponent(await textInput.getAttribute('value')); + const reportURL = decodeURIComponent((await textInput.getAttribute('value')) ?? ''); // get number of filters in URLs const timeFiltersNumberInReportURL = diff --git a/x-pack/test_serverless/functional/test_suites/common/examples/search_examples/partial_results_example.ts b/x-pack/test_serverless/functional/test_suites/common/examples/search_examples/partial_results_example.ts index 6e8fbb465bb08..727551308b0b9 100644 --- a/x-pack/test_serverless/functional/test_suites/common/examples/search_examples/partial_results_example.ts +++ b/x-pack/test_serverless/functional/test_suites/common/examples/search_examples/partial_results_example.ts @@ -30,7 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await testSubjects.click('requestFibonacci'); await retry.waitFor('update progress bar', async () => { - const newValue = await progressBar.getAttribute('value'); + const newValue = (await progressBar.getAttribute('value')) ?? ''; return parseFloat(newValue) > 0; }); });