Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions tests/playwright/support/utils/password-confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import type { Page } from '@playwright/test'

import { expect } from '@playwright/test'

/**
* Handle the password confirmation dialog if it appears
*
Expand All @@ -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 })

@odzhychko odzhychko Jul 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I'm not too to familiar with best-practices for Playwright.

But I'm pretty sure, expect should only be used for real assertions.

My research with Claude Opus 4.8 suggest to use waitFor. So something like this should work as expected:

const dialogVisible = await dialog
  .waitFor({ state: "visible", timeout: 500 })
  .then(() => true)
  .catch(() => false);

if (!dialogVisible) {
  return;
}

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" });

.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.
})
Comment on lines +19 to +27

@susnux susnux Jul 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a async function so please use proper try {} catch {} blocks :)

Suggested change
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.
})
try {
await expect(dialog).toBeVisible({ timeout: 500 })
await dialog.locator('input[type="password"]').fill(password)
await dialog.getByRole('button', { name: 'Confirm' }).click()
await expect(dialog).toBeHidden()
} catch {
// Dialog didn't appear — some operations don't require confirmation.
}

}
Loading