diff --git a/tests/playwright/support/utils/password-confirmation.ts b/tests/playwright/support/utils/password-confirmation.ts index 9524f1f5094f2..8da7ff7047f50 100644 --- a/tests/playwright/support/utils/password-confirmation.ts +++ b/tests/playwright/support/utils/password-confirmation.ts @@ -5,6 +5,8 @@ import type { Page } from '@playwright/test' +import { expect } from '@playwright/test' + /** * Handle the password confirmation dialog if it appears * @@ -14,21 +16,13 @@ import type { Page } from '@playwright/test' export async function handlePasswordConfirmation(page: Page, password = 'admin') { const dialog = page.locator('.modal-container:has-text("Authentication required")') - try { - // Check if the dialog exists within a short timeout - const dialogVisible = await dialog.isVisible({ timeout: 500 }).catch(() => false) - - if (dialogVisible) { - // Fill the password field + await expect(dialog).toBeVisible({ timeout: 500 }) + .then(async () => { await dialog.locator('input[type="password"]').fill(password) - - // Click the confirm button await dialog.getByRole('button', { name: 'Confirm' }).click() - - // Wait for the dialog to disappear - await dialog.waitFor({ state: 'hidden' }) - } - } catch { - // Dialog didn't appear, which is fine - some operations might not require confirmation - } + await expect(dialog).toBeHidden() + }) + .catch(() => { + // Dialog didn't appear — some operations don't require confirmation. + }) }