From 3a5f5626b2c3631eb2646782937171d2f87ce525 Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Thu, 22 Dec 2022 19:44:11 +0100 Subject: [PATCH] Ensure that API keys are rendered before performing bulk delete in functional tests. (#148013) --- .../api_keys_grid/api_keys_grid_page.test.tsx | 2 +- .../api_keys_grid/api_keys_grid_page.tsx | 2 +- .../test/functional/apps/api_keys/home_page.ts | 18 ++++++++++++++++-- .../functional/page_objects/api_keys_page.ts | 6 +++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx index f442c464ff0b2..0f20e4a5cfe96 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx @@ -116,7 +116,7 @@ describe('APIKeysGridPage', () => { const secondKey = getByText(/second-api-key/).closest('td'); const secondKeyEuiLink = secondKey!.querySelector('button'); expect(secondKeyEuiLink).not.toBeNull(); - expect(secondKeyEuiLink!.getAttribute('data-test-subj')).toBe('roleRowName-second-api-key'); + expect(secondKeyEuiLink!.getAttribute('data-test-subj')).toBe('apiKeyRowName-second-api-key'); }); afterAll(() => { diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx index 0993e88e7ab16..49b606c7b34cd 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx @@ -518,7 +518,7 @@ export class APIKeysGridPage extends Component { return ( { this.setState({ selectedApiKey: recordAP, isUpdateFlyoutVisible: true }); }} diff --git a/x-pack/test/functional/apps/api_keys/home_page.ts b/x-pack/test/functional/apps/api_keys/home_page.ts index c984f58dc6cc1..dee8f2af4a58a 100644 --- a/x-pack/test/functional/apps/api_keys/home_page.ts +++ b/x-pack/test/functional/apps/api_keys/home_page.ts @@ -17,6 +17,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const testSubjects = getService('testSubjects'); const find = getService('find'); const browser = getService('browser'); + const retry = getService('retry'); const testRoles: Record = { viewer: { @@ -37,8 +38,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }, }; - // Failing: See https://github.com/elastic/kibana/issues/141868 - describe.skip('Home page', function () { + async function ensureApiKeysExist(apiKeysNames: string[]) { + await retry.try(async () => { + for (const apiKeyName of apiKeysNames) { + log.debug(`Checking if API key ("${apiKeyName}") exists.`); + await pageObjects.apiKeys.ensureApiKeyExists(apiKeyName); + log.debug(`API key ("${apiKeyName}") exists.`); + } + }); + } + + describe('Home page', function () { before(async () => { await clearAllApiKeys(es, log); await security.testUser.setRoles(['kibana_admin']); @@ -392,6 +402,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.apiKeys.clickOnPromptCreateApiKey(); await pageObjects.apiKeys.setApiKeyName('api key 1'); await pageObjects.apiKeys.clickSubmitButtonOnApiKeyFlyout(); + await ensureApiKeysExist(['api key 1']); }); it('one by one', async () => { @@ -406,6 +417,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.apiKeys.setApiKeyName('api key 2'); await pageObjects.apiKeys.clickSubmitButtonOnApiKeyFlyout(); + // Make sure all API keys we want to delete are created and rendered. + await ensureApiKeysExist(['api key 1', 'api key 2']); + await pageObjects.apiKeys.bulkDeleteApiKeys(); expect(await pageObjects.apiKeys.getApiKeysFirstPromptTitle()).to.be( 'Create your first API key' diff --git a/x-pack/test/functional/page_objects/api_keys_page.ts b/x-pack/test/functional/page_objects/api_keys_page.ts index 6f5bfb5078133..85e8188ee747a 100644 --- a/x-pack/test/functional/page_objects/api_keys_page.ts +++ b/x-pack/test/functional/page_objects/api_keys_page.ts @@ -103,7 +103,11 @@ export function ApiKeysPageProvider({ getService }: FtrProviderContext) { }, async clickExistingApiKeyToOpenFlyout(apiKeyName: string) { - await testSubjects.click(`roleRowName-${apiKeyName}`); + await testSubjects.click(`apiKeyRowName-${apiKeyName}`); + }, + + async ensureApiKeyExists(apiKeyName: string) { + await testSubjects.existOrFail(`apiKeyRowName-${apiKeyName}`); }, async getMetadataSwitch() {