From 77455d73e8743fd543e54271e56ab9b408d012ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20=C3=81brah=C3=A1m?= Date: Fri, 9 Aug 2024 15:37:59 +0200 Subject: [PATCH] testing some options to decrease flakiness --- .../integrations/artifact_entries_list.ts | 103 +++++++++++++++--- .../apps/integrations/mocks.ts | 2 +- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/x-pack/test/security_solution_endpoint/apps/integrations/artifact_entries_list.ts b/x-pack/test/security_solution_endpoint/apps/integrations/artifact_entries_list.ts index 11c0b1db59665..9053b5e7c1586 100644 --- a/x-pack/test/security_solution_endpoint/apps/integrations/artifact_entries_list.ts +++ b/x-pack/test/security_solution_endpoint/apps/integrations/artifact_entries_list.ts @@ -147,11 +147,24 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { actions: | ArtifactActionsType['create']['formFields'] | ArtifactActionsType['update']['formFields'], - suffix?: string + suffix?: string, + byText?: boolean, + waitABit?: boolean ) => { for (const formAction of actions) { if (formAction.type === 'customClick') { - await find.clickByCssSelector(formAction.selector, testSubjects.FIND_TIME); + if (waitABit) { + await new Promise((resolve) => setTimeout(resolve, 500)); + } + + if (byText) { + await find.clickByButtonText(formAction.selector, undefined, testSubjects.FIND_TIME); + } else { + await find.clickByCssSelector( + `button[title="${formAction.selector}"]`, + testSubjects.FIND_TIME + ); + } } else if (formAction.type === 'click') { await testSubjects.click(formAction.selector); } else if (formAction.type === 'input') { @@ -179,24 +192,72 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const createArtifact = async ( actions: ArtifactActionsType | MultipleArtifactActionsType, - options?: { policyId?: string; suffix?: string; createButton?: string } - ) => { - // Opens add flyout - if (options?.createButton) { - await testSubjects.click(`${actions.pagePrefix}-${options.createButton}`); - } else { - await testSubjects.click(`${actions.pagePrefix}-emptyState-addButton`); + options?: { + policyId?: string; + suffix?: string; + createButton?: string; + byText?: boolean; + waitABit?: boolean; } + ) => { + let successes = 0; + let fails = 0; + + for (let i = 0; i < 3; i++) { + // Opens add flyout + if (options?.createButton) { + await testSubjects.click(`${actions.pagePrefix}-${options.createButton}`); + } else { + await testSubjects.click(`${actions.pagePrefix}-emptyState-addButton`); + } - await performActions(actions.create.formFields, options?.suffix); + await performActions( + actions.create.formFields, + options?.suffix, + options?.byText, + options?.waitABit + ); - if (options?.policyId) { - await testSubjects.click(`${actions.pageObject}-form-effectedPolicies-perPolicy`); - await testSubjects.click(`policy-${options.policyId}-checkbox`); + if (options?.policyId) { + await testSubjects.click(`${actions.pageObject}-form-effectedPolicies-perPolicy`); + await testSubjects.click(`policy-${options.policyId}-checkbox`); + } + + let hasFailed = false; + try { + await find.byCssSelector( + ':not([disabled])[data-test-subj="EventFiltersListPage-flyout-submitButton"]', + 2000 + ); + } catch (e) { + hasFailed = true; + } + + if (hasFailed) { + fails++; + } else { + successes++; + } + console.log( + '🧀 🥭 IN PROGRESS', + JSON.stringify( + { byText: options?.byText, waitABit: options?.waitABit, hasFailed, fails, successes }, + null, + ' ' + ) + ); + + await testSubjects.click(`${actions.pagePrefix}-flyout-cancelButton`); } - // Submit create artifact form - await testSubjects.click(`${actions.pagePrefix}-flyout-submitButton`); + console.log( + '🧀 🥭 RESULTS ARE IN', + JSON.stringify( + { byText: options?.byText, waitABit: options?.waitABit, fails, successes }, + null, + ' ' + ) + ); }; const updateArtifact = async ( @@ -218,7 +279,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await testSubjects.click(`${actions.pagePrefix}-flyout-submitButton`); }; - for (const testData of getArtifactsListTestsData()) { + for (const testData of [[...getArtifactsListTestsData()][1]]) { describe(`When on the ${testData.title} entries list`, function () { beforeEach(async () => { policyInfo = await policyTestResources.createPolicy(); @@ -234,6 +295,16 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { } }); + it.only('flaky test for clicking by css selector', async () => { + await createArtifact(testData, { policyId: policyInfo.packagePolicy.id }); + }); + it.only('flaky test for clicking by text', async () => { + await createArtifact(testData, { policyId: policyInfo.packagePolicy.id, byText: true }); + }); + it.only('flaky test for some wait', async () => { + await createArtifact(testData, { policyId: policyInfo.packagePolicy.id, waitABit: true }); + }); + it(`should not show page title if there is no ${testData.title} entry`, async () => { await testSubjects.missingOrFail('header-page-title'); }); diff --git a/x-pack/test/security_solution_endpoint/apps/integrations/mocks.ts b/x-pack/test/security_solution_endpoint/apps/integrations/mocks.ts index fa76aaa72ceb0..4b0dc92ab986d 100644 --- a/x-pack/test/security_solution_endpoint/apps/integrations/mocks.ts +++ b/x-pack/test/security_solution_endpoint/apps/integrations/mocks.ts @@ -223,7 +223,7 @@ export const getArtifactsListTestsData = () => [ }, { type: 'customClick', - selector: 'button[title="agent.ephemeral_id"]', + selector: 'agent.ephemeral_id', }, { type: 'click',