From abcb09dfe3d04bde2145ab185d2c8776e35f76b2 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 17 Jul 2026 19:22:35 +0200 Subject: [PATCH] test(users): prevent flaky tests with hardcoded values - Do not use hard coded user-id. - Properly clean-up created user in `finally` clause Signed-off-by: Ferdinand Thiessen --- tests/playwright/e2e/users/users.spec.ts | 27 +++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/playwright/e2e/users/users.spec.ts b/tests/playwright/e2e/users/users.spec.ts index 1b009daf2bae5..bb5731393f20d 100644 --- a/tests/playwright/e2e/users/users.spec.ts +++ b/tests/playwright/e2e/users/users.spec.ts @@ -12,22 +12,25 @@ import { handlePasswordConfirmation } from '../../support/utils/password-confirm test.describe('Settings: Create and delete accounts', () => { test('can create a user with username and password', async ({ page }) => { - const settingsPage = new SettingsUsersPage(page) - await settingsPage.open() - - await settingsPage.openNewUserDialog() + const newUserId = crypto.randomUUID() + try { + const settingsPage = new SettingsUsersPage(page) + await settingsPage.open() - const dialog = settingsPage.newUserDialog() - await dialog.getByLabel(/Account name/).fill('newuser-basic') - await dialog.getByLabel(/Password/).and(page.locator('input')).fill('password123') + await settingsPage.openNewUserDialog() - await dialog.getByRole('button', { name: 'Add new account' }).click() - await handlePasswordConfirmation(page) - await dialog.waitFor({ state: 'hidden' }) + const dialog = settingsPage.newUserDialog() + await dialog.getByLabel(/Account name/).fill(newUserId) + await dialog.getByLabel(/Password/).and(page.locator('input')).fill('password123') - await expect(settingsPage.userRow('newuser-basic')).toContainText('newuser-basic') + await dialog.getByRole('button', { name: 'Add new account' }).click() + await handlePasswordConfirmation(page) + await dialog.waitFor({ state: 'hidden' }) - await runOcc(['user:delete', 'newuser-basic']) + await expect(settingsPage.userRow(newUserId)).toContainText(newUserId) + } finally { + await runOcc(['user:delete', newUserId], { failOnError: false }) + } }) test('can create a user with display name and email', async ({ page }) => {