From 70b9cab3932ae3ec02ca3309c3890ea3f1652d65 Mon Sep 17 00:00:00 2001 From: Said Akhrarov <36972061+akhrarovsaid@users.noreply.github.com> Date: Fri, 28 Mar 2025 21:02:05 -0400 Subject: [PATCH] test: deflake indexed e2e (#11911) ### What? This PR aims to deflake the indexed fields e2e test in `test/fields/collections/Indexed/e2e.spec.ts`. The issue is that this test is setup in a way where sometimes two toasts will present themselves in the ui. The second toast assertion will fail with a strict mode violation as the toast locator will resolve to two elements. ### Why? To prevent this test from flaking in ci. ### How? Adding a new `dismissAfterAssertion` flag to the `assertToastErrors` helper function which dismisses the toasts. This way, the toasts will not raise the aforementioned error as they will be dismissed from the ui. The logic is handled in a separate loop through such that the assertions occur first. This is done so that dismissing a toast does not surface errors due to the order of toasts being shown changing. --- test/fields/collections/Indexed/e2e.spec.ts | 1 + test/helpers/assertToastErrors.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/test/fields/collections/Indexed/e2e.spec.ts b/test/fields/collections/Indexed/e2e.spec.ts index b0954cfbb2..cb90de6806 100644 --- a/test/fields/collections/Indexed/e2e.spec.ts +++ b/test/fields/collections/Indexed/e2e.spec.ts @@ -100,6 +100,7 @@ describe('Radio', () => { await assertToastErrors({ page, errors: ['uniqueText'], + dismissAfterAssertion: true, }) await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create') diff --git a/test/helpers/assertToastErrors.ts b/test/helpers/assertToastErrors.ts index cc39c0e11e..3d1667184c 100644 --- a/test/helpers/assertToastErrors.ts +++ b/test/helpers/assertToastErrors.ts @@ -5,7 +5,9 @@ import { expect } from '@playwright/test' export async function assertToastErrors({ page, errors, + dismissAfterAssertion, }: { + dismissAfterAssertion?: boolean errors: string[] page: Page }): Promise { @@ -24,4 +26,13 @@ export async function assertToastErrors({ ).toHaveText(error) } } + + if (dismissAfterAssertion) { + const closeButtons = page.locator('.payload-toast-container button.payload-toast-close-button') + const count = await closeButtons.count() + + for (let i = 0; i < count; i++) { + await closeButtons.nth(i).click() + } + } }