From 9089dbebca2fe6da6d19cb2afa8b0b4e55c68298 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 10 Dec 2024 15:28:00 +0100 Subject: [PATCH] [Synthetics] Update e2e flaky test !! (#203397) ## Summary Update e2e flaky test !! --- .../journeys/add_monitor.journey.ts | 2 +- .../journeys/overview_sorting.journey.ts | 141 ++++++++++-------- .../page_objects/synthetics_app.tsx | 41 +++-- 3 files changed, 97 insertions(+), 87 deletions(-) diff --git a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/add_monitor.journey.ts b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/add_monitor.journey.ts index ca4806ebdd5ae..c7dcc6742d7d6 100644 --- a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/add_monitor.journey.ts +++ b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/add_monitor.journey.ts @@ -201,7 +201,7 @@ const createMonitorJourney = ({ await syntheticsApp.createMonitor({ monitorConfig, monitorType }); await page.waitForSelector('text=Monitor name already exists'); await syntheticsApp.clickByTestSubj('syntheticsMonitorConfigSubmitButton'); - await page.waitForSelector('text=Cancel'); + await page.click('text=Cancel'); }); step('delete monitor', async () => { diff --git a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/overview_sorting.journey.ts b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/overview_sorting.journey.ts index 67ce82624f518..16a0f2bf5453f 100644 --- a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/overview_sorting.journey.ts +++ b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/overview_sorting.journey.ts @@ -6,6 +6,7 @@ */ import { before, expect, journey, step } from '@elastic/synthetics'; +import { RetryService } from '@kbn/ftr-common-functional-services'; import { addTestMonitor, cleanTestMonitors, @@ -19,6 +20,8 @@ journey('OverviewSorting', async ({ page, params }) => { const testMonitor2 = 'aCd'; // third alpha, second created const testMonitor3 = 'Abc'; // first alpha, last created + const retry: RetryService = params.getService('retry'); + before(async () => { await enableMonitorManagedViaApi(params.kibanaUrl); await cleanTestMonitors(params); @@ -42,83 +45,91 @@ journey('OverviewSorting', async ({ page, params }) => { }); step('sort alphabetical asc', async () => { - await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); - await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); - await page.click('button:has-text("Alphabetical")'); - await page.waitForSelector(`text=${testMonitor1}`); - await page.waitForSelector(`text=${testMonitor2}`); - await page.waitForSelector(`text=${testMonitor3}`); - const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); - const first = await gridItems.nth(0); - const second = await gridItems.nth(1); - const third = await gridItems.nth(2); - const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor3}')`); - const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor1}')`); - const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor2}')`); - expect(await correctFirstMonitor.count()).toBe(1); - expect(await correctSecondMonitor.count()).toBe(1); - expect(await correctThirdMonitor.count()).toBe(1); + await retry.try(async () => { + await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); + await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); + await page.click('button:has-text("Alphabetical")'); + await page.waitForSelector(`text=${testMonitor1}`); + await page.waitForSelector(`text=${testMonitor2}`); + await page.waitForSelector(`text=${testMonitor3}`); + const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); + const first = await gridItems.nth(0); + const second = await gridItems.nth(1); + const third = await gridItems.nth(2); + const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor3}')`); + const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor1}')`); + const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor2}')`); + expect(await correctFirstMonitor.count()).toBe(1); + expect(await correctSecondMonitor.count()).toBe(1); + expect(await correctThirdMonitor.count()).toBe(1); + }); }); step('sort alphabetical desc', async () => { - await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); - await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); - await page.click('button:has-text("Z -> A")'); - await page.waitForSelector(`text=${testMonitor1}`); - await page.waitForSelector(`text=${testMonitor2}`); - await page.waitForSelector(`text=${testMonitor3}`); - const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); - const first = await gridItems.nth(0); - const second = await gridItems.nth(1); - const third = await gridItems.nth(2); - const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor2}')`); - const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor1}')`); - const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor3}')`); - expect(await correctFirstMonitor.count()).toBe(1); - expect(await correctSecondMonitor.count()).toBe(1); - expect(await correctThirdMonitor.count()).toBe(1); + await retry.try(async () => { + await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); + await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); + await page.click('button:has-text("Z -> A")'); + await page.waitForSelector(`text=${testMonitor1}`); + await page.waitForSelector(`text=${testMonitor2}`); + await page.waitForSelector(`text=${testMonitor3}`); + const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); + const first = await gridItems.nth(0); + const second = await gridItems.nth(1); + const third = await gridItems.nth(2); + const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor2}')`); + const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor1}')`); + const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor3}')`); + expect(await correctFirstMonitor.count()).toBe(1); + expect(await correctSecondMonitor.count()).toBe(1); + expect(await correctThirdMonitor.count()).toBe(1); + }); }); step('sort last updated asc', async () => { - await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); - await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); - await page.click('button:has-text("Last modified")'); - await page.waitForSelector(`text=${testMonitor1}`); - await page.waitForSelector(`text=${testMonitor2}`); - await page.waitForSelector(`text=${testMonitor3}`); - const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); - const first = await gridItems.nth(0); - const second = await gridItems.nth(1); - const third = await gridItems.nth(2); - const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor3}')`); - const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor2}')`); - const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor1}')`); - expect(await correctFirstMonitor.count()).toBe(1); - expect(await correctSecondMonitor.count()).toBe(1); - expect(await correctThirdMonitor.count()).toBe(1); + await retry.try(async () => { + await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); + await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); + await page.click('button:has-text("Last modified")'); + await page.waitForSelector(`text=${testMonitor1}`); + await page.waitForSelector(`text=${testMonitor2}`); + await page.waitForSelector(`text=${testMonitor3}`); + const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); + const first = await gridItems.nth(0); + const second = await gridItems.nth(1); + const third = await gridItems.nth(2); + const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor3}')`); + const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor2}')`); + const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor1}')`); + expect(await correctFirstMonitor.count()).toBe(1); + expect(await correctSecondMonitor.count()).toBe(1); + expect(await correctThirdMonitor.count()).toBe(1); + }); }); step('sort last updated desc', async () => { - await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); - await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); - await page.click('button:has-text("Oldest first")'); - await page.waitForSelector(`text=${testMonitor1}`); - await page.waitForSelector(`text=${testMonitor2}`); - await page.waitForSelector(`text=${testMonitor3}`); - const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); - const first = await gridItems.nth(0); - const second = await gridItems.nth(1); - const third = await gridItems.nth(2); - const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor1}')`); - const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor2}')`); - const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor3}')`); - expect(await correctFirstMonitor.count()).toBe(1); - expect(await correctSecondMonitor.count()).toBe(1); - expect(await correctThirdMonitor.count()).toBe(1); + await retry.try(async () => { + await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); + await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); + await page.click('button:has-text("Oldest first")'); + await page.waitForSelector(`text=${testMonitor1}`); + await page.waitForSelector(`text=${testMonitor2}`); + await page.waitForSelector(`text=${testMonitor3}`); + const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`); + const first = await gridItems.nth(0); + const second = await gridItems.nth(1); + const third = await gridItems.nth(2); + const correctFirstMonitor = await first.locator(`button:has-text('${testMonitor1}')`); + const correctSecondMonitor = await second.locator(`button:has-text('${testMonitor2}')`); + const correctThirdMonitor = await third.locator(`button:has-text('${testMonitor3}')`); + expect(await correctFirstMonitor.count()).toBe(1); + expect(await correctSecondMonitor.count()).toBe(1); + expect(await correctThirdMonitor.count()).toBe(1); + }); }); step('delete monitors', async () => { - await syntheticsApp.navigateToMonitorManagement(); + await page.getByTestId('syntheticsMonitorManagementTab').click(); expect(await syntheticsApp.deleteMonitors()).toBeTruthy(); }); }); diff --git a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/page_objects/synthetics_app.tsx b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/page_objects/synthetics_app.tsx index 931694da554ca..f9eb448615de8 100644 --- a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/page_objects/synthetics_app.tsx +++ b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/page_objects/synthetics_app.tsx @@ -128,28 +128,26 @@ export function syntheticsAppPageProvider({ }, async deleteMonitors() { - let isSuccessful: boolean = false; - while (true) { - if ( - !(await page.isVisible(this.byTestId('euiCollapsedItemActionsButton'), { timeout: 0 })) - ) { - isSuccessful = true; - break; - } - await page.click(this.byTestId('euiCollapsedItemActionsButton'), { - delay: 800, - force: true, - }); - await page.click(`.euiContextMenuPanel ${this.byTestId('syntheticsMonitorDeleteAction')}`, { - delay: 800, - }); - await page.waitForSelector('[data-test-subj="confirmModalTitleText"]'); - await this.clickByTestSubj('confirmModalConfirmButton'); - isSuccessful = Boolean(await this.findByTestSubj('uptimeDeleteMonitorSuccess')); - await this.navigateToMonitorManagement(); - await page.waitForTimeout(5 * 1000); + if (!page.url().includes('monitors/management')) { + return true; } - return isSuccessful; + await page.getByTestId('euiCollapsedItemActionsButton').first().click(); + await page.click(`.euiContextMenuPanel ${this.byTestId('syntheticsMonitorDeleteAction')}`, { + delay: 800, + }); + await page.waitForSelector('[data-test-subj="confirmModalTitleText"]'); + await page.getByTestId('confirmModalConfirmButton').click(); + await page.getByTestId('uptimeDeleteMonitorSuccess').click(); + await page.getByTestId('syntheticsRefreshButtonButton').click(); + + await page.getByTestId('checkboxSelectAll').click(); + await page + .getByTestId('syntheticsBulkOperationPopoverClickMeToLoadAContextMenuButton') + .click(); + + await page.getByTestId('confirmModalConfirmButton').click(); + + return true; }, async navigateToEditMonitor(monitorName: string) { @@ -387,6 +385,7 @@ export function syntheticsAppPageProvider({ await button?.click(); } }, + async checkIsEnabled() { await page.waitForTimeout(5 * 1000); const addMonitorBtn = await this.getAddMonitorButton();