From ad17f7aafc409d4aa604a45bca6ecd62276be3b0 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:37:26 +1100 Subject: [PATCH] [8.x] [Index Management FTR] Improve delete indices test (#200941) (#201319) # Backport This will backport the following commits from `main` to `8.x`: - [[Index Management FTR] Improve delete indices test (#200941)](https://github.com/elastic/kibana/pull/200941) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Elena Stoeva <59341489+ElenaStoeva@users.noreply.github.com> --- .../page_objects/index_management_page.ts | 35 ++++++++++++++----- .../management/index_management/indices.ts | 5 ++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/x-pack/test/functional/page_objects/index_management_page.ts b/x-pack/test/functional/page_objects/index_management_page.ts index 8053293f98633..3b2da84492032 100644 --- a/x-pack/test/functional/page_objects/index_management_page.ts +++ b/x-pack/test/functional/page_objects/index_management_page.ts @@ -199,14 +199,33 @@ export function IndexManagementPageProvider({ getService }: FtrProviderContext) }, async expectIndexIsDeleted(indexName: string) { - const table = await find.byCssSelector('table'); - const rows = await table.findAllByTestSubject('indexTableRow'); - const indexNames: string[] = await Promise.all( - rows.map(async (row) => { - return await (await row.findByTestSubject('indexTableIndexNameLink')).getVisibleText(); - }) - ); - expect(indexNames.includes(indexName)).to.be(false); + try { + const table = await find.byCssSelector('table'); + const rows = await table.findAllByTestSubject('indexTableRow'); + + const indexNames = await Promise.all( + rows.map(async (row) => { + try { + return await ( + await row.findByTestSubject('indexTableIndexNameLink') + ).getVisibleText(); + } catch (error) { + // If the current row is stale, it has already been removed + if (error.name === 'StaleElementReferenceError') return undefined; + throw error; // Rethrow unexpected errors + } + }) + ).then((names) => names.filter((name) => name !== undefined)); + + expect(indexNames.includes(indexName)).to.be(false); + } catch (error) { + if (error.name === 'StaleElementReferenceError') { + // If the table itself is stale, it means all rows have been removed + return; // Pass the test since the table is gone + } else { + throw error; // Rethrow unexpected errors + } + } }, async manageIndex(indexName: string) { const id = `checkboxSelectIndex-${indexName}`; diff --git a/x-pack/test_serverless/functional/test_suites/common/management/index_management/indices.ts b/x-pack/test_serverless/functional/test_suites/common/management/index_management/indices.ts index 0d8f091123627..a88d1977a0abb 100644 --- a/x-pack/test_serverless/functional/test_suites/common/management/index_management/indices.ts +++ b/x-pack/test_serverless/functional/test_suites/common/management/index_management/indices.ts @@ -15,6 +15,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const esDeleteAllIndices = getService('esDeleteAllIndices'); const testIndexName = `index-ftr-test-${Math.random()}`; const es = getService('es'); + const retry = getService('retry'); describe('Indices', function () { this.tags(['skipSvlSearch']); @@ -73,7 +74,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); it('can delete index', async () => { await pageObjects.indexManagement.confirmDeleteModalIsVisible(); - await pageObjects.indexManagement.expectIndexIsDeleted(testIndexName); + await retry.try(async () => { + await pageObjects.indexManagement.expectIndexIsDeleted(testIndexName); + }); }); }); });