From a2e23f6dee9cb2ad0115f1b7426d7345c7cdfd18 Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Fri, 23 Dec 2022 12:46:47 +0100 Subject: [PATCH] [7.17] Ensure that API keys are rendered before performing bulk delete in functional tests. (#148013) (#148047) # Backport This will backport the following commits from `main` to `7.17`: - [Ensure that API keys are rendered before performing bulk delete in functional tests. (#148013)](https://github.com/elastic/kibana/pull/148013) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --- .../api_keys/api_keys_grid/api_keys_grid_page.tsx | 1 + x-pack/test/functional/apps/api_keys/home_page.ts | 15 +++++++++++++++ .../test/functional/page_objects/api_keys_page.ts | 11 +++++++++++ 3 files changed, 27 insertions(+) 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 fddf52080b4ee..416dcee9d35ae 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 @@ -491,6 +491,7 @@ export class APIKeysGridPage extends Component { defaultMessage: 'Name', }), sortable: true, + 'data-test-subj': 'apiKeyNameCell', }, ]); 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 5907247527585..e29cfd55da686 100644 --- a/x-pack/test/functional/apps/api_keys/home_page.ts +++ b/x-pack/test/functional/apps/api_keys/home_page.ts @@ -15,6 +15,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const testSubjects = getService('testSubjects'); const find = getService('find'); const browser = getService('browser'); + const retry = getService('retry'); + + 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 () => { @@ -101,6 +112,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.apiKeys.clickOnPromptCreateApiKey(); await pageObjects.apiKeys.setApiKeyName('api key 1'); await pageObjects.apiKeys.submitOnCreateApiKey(); + await ensureApiKeysExist(['api key 1']); }); it('one by one', async () => { @@ -115,6 +127,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.apiKeys.setApiKeyName('api key 2'); await pageObjects.apiKeys.submitOnCreateApiKey(); + // 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 9349eaa4bda0c..cf7f76a810ce7 100644 --- a/x-pack/test/functional/page_objects/api_keys_page.ts +++ b/x-pack/test/functional/page_objects/api_keys_page.ts @@ -92,5 +92,16 @@ export function ApiKeysPageProvider({ getService }: FtrProviderContext) { await testSubjects.click('confirmModalConfirmButton'); } }, + + async ensureApiKeyExists(apiKeyName: string) { + const existingApiKeyNameCells = await testSubjects.findAll('apiKeyNameCell'); + for (const existingApiKeyNameCell of existingApiKeyNameCells) { + if (apiKeyName === (await existingApiKeyNameCell.getVisibleText())) { + return; + } + } + + throw new Error(`API key ("${apiKeyName}") does not exist.`); + }, }; }