Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor tests to avoid static waits to improve run speed (#1404)

Leendert de Borstd6cf8421f33a
diff --git a/apps/browser-extension/tests/e2e/04-create-credential.spec.ts b/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
index bc0f0110f..62d3f0276 100644
--- a/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
+++ b/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
@@ -9,6 +9,7 @@ import {
navigateToVault,
navigateToAddCredentialForm,
verifyCredentialExists,
+ waitForVaultReady,
FieldSelectors,
ButtonSelectors,
} from '../fixtures';
@@ -87,8 +88,8 @@ test.describe.serial('4. Create Credential', () => {
// Navigate back to the Vault tab
await navigateToVault(popup);
- // Wait for credentials list to load
- await popup.waitForTimeout(500);
+ // Wait for vault to be ready
+ await waitForVaultReady(popup);
// Verify our created credential appears in the list
await verifyCredentialExists(popup, testCredentialName);
diff --git a/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts b/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
index 75a59236f..3eed3b5bf 100644
--- a/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
+++ b/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
@@ -12,8 +12,10 @@ import {
verifyCredentialExists,
verifyVaultItemCount,
cleanupClients,
+ waitForVaultReady,
FieldSelectors,
ButtonSelectors,
+ waitForCredentialSaved,
} from '../fixtures';
/**
@@ -112,11 +114,8 @@ test.describe.serial('5. Vault Merge', () => {
// Click Save button
await popup.click(ButtonSelectors.SAVE);
- // Wait for either:
- // 1. Navigation to item details page (success)
- // 2. Navigation back to vault list (merge happened, redirected)
- // 3. Stay on form with error (sync conflict)
- await popup.waitForTimeout(100);
+ // Wait for vault to be ready after save/merge
+ await waitForCredentialSaved(popup, credentialNameB);
// Take a screenshot to see current state
await popup.screenshot({ path: 'tests/screenshots/5.3-client-b-after-save.png' });
@@ -128,9 +127,6 @@ test.describe.serial('5. Vault Merge', () => {
// Navigate back to the Vault tab
await navigateToVault(popup);
- // Wait for the credentials list to load
- await popup.waitForTimeout(100);
-
// Take a screenshot first to see what's there
await popup.screenshot({ path: 'tests/screenshots/5.4-client-b-vault-state.png' });
@@ -157,15 +153,12 @@ test.describe.serial('5. Vault Merge', () => {
// Navigate to the Vault tab (this should trigger a sync/refresh)
await navigateToVault(popup);
- // Wait a moment for sync to complete
- await popup.waitForTimeout(2000);
+ // Wait for Client A's original credential to be visible (indicates vault is ready)
+ await verifyCredentialExists(popup, credentialNameA);
// Take a screenshot first to see what's there
await popup.screenshot({ path: 'tests/screenshots/5.5-client-a-vault-state.png' });
- // Verify Client A's original credential exists
- await verifyCredentialExists(popup, credentialNameA);
-
// Check if Client B's credential also synced
const clientBCredential = popup.locator(`text=${credentialNameB}`);
const hasBothCredentials = await clientBCredential.isVisible().catch(() => false);
diff --git a/apps/browser-extension/tests/e2e/06-field-level-merge.spec.ts b/apps/browser-extension/tests/e2e/06-field-level-merge.spec.ts
index 96061ecfc..59b1e155e 100644
--- a/apps/browser-extension/tests/e2e/06-field-level-merge.spec.ts
+++ b/apps/browser-extension/tests/e2e/06-field-level-merge.spec.ts
@@ -19,6 +19,7 @@ import {
fillPassword,
fillNotes,
cleanupClients,
+ waitForVaultReady,
FieldSelectors,
} from '../fixtures';
@@ -83,7 +84,6 @@ test.describe.serial('6. Field-Level Merge', () => {
test('6.2 Both clients sync and verify credential exists', async () => {
// Client A navigates to vault and waits for sync
await navigateToVault(clientA.popup);
- await clientA.popup.waitForTimeout(100);
// Take screenshot to debug what's visible
await clientA.popup.screenshot({ path: 'tests/screenshots/6.2-client-a-vault.png' });
@@ -91,6 +91,7 @@ test.describe.serial('6. Field-Level Merge', () => {
// Let Client B navigate to root so it will sync and see the credential
await navigateToRoot(clientB.popup);
+ await waitForVaultReady(clientB.popup);
await verifyCredentialExists(clientB.popup, credentialName);
});
@@ -109,12 +110,9 @@ test.describe.serial('6. Field-Level Merge', () => {
await popup.screenshot({ path: 'tests/screenshots/6.3-client-a-before-save.png' });
- // Save the credential
+ // Save the credential (saveCredential now waits for completion)
await saveCredential(popup);
- // Wait for save to complete
- await popup.waitForTimeout(500);
-
await popup.screenshot({ path: 'tests/screenshots/6.3-client-a-after-save.png' });
});
@@ -148,7 +146,6 @@ test.describe.serial('6. Field-Level Merge', () => {
// Navigate to vault
await navigateToVault(popup);
- await popup.waitForTimeout(100);
// Click on credential to view merged details
await clickCredential(popup, credentialName);
@@ -172,7 +169,8 @@ test.describe.serial('6. Field-Level Merge', () => {
// Navigate back
await popup.goBack();
- await popup.waitForTimeout(100);
+ // Wait for the credential list to be visible
+ await verifyCredentialExists(popup, credentialName);
});
test('6.6 Client A syncs and verifies merged credential', async () => {
diff --git a/apps/browser-extension/tests/e2e/07-offline-sync.spec.ts b/apps/browser-extension/tests/e2e/07-offline-sync.spec.ts
index f888df7e6..e332936a7 100644
--- a/apps/browser-extension/tests/e2e/07-offline-sync.spec.ts
+++ b/apps/browser-extension/tests/e2e/07-offline-sync.spec.ts
@@ -16,6 +16,10 @@ import {
enableOfflineMode,
disableOfflineMode,
waitForOfflineIndicator,
+ waitForSettingsPage,
+ waitForUnlockPage,
+ waitForVaultReady,
+ waitForCredentialSaved,
FieldSelectors,
ButtonSelectors,
} from '../fixtures';
@@ -101,14 +105,11 @@ test.describe.serial('7. Offline Sync', () => {
// Navigate to root to trigger the offline detection
await navigateToRoot(popup);
- // Wait for the extension to detect offline status
- await popup.waitForTimeout(1000);
+ // The offline indicator should be visible (this is the smart wait)
+ await waitForOfflineIndicator(popup, 10000);
// Take a screenshot to see the offline state
await popup.screenshot({ path: 'tests/screenshots/7.3-client-b-offline-mode.png' });
-
- // The offline indicator should be visible
- await waitForOfflineIndicator(popup, 10000);
});
test('7.4 Client B creates a credential while offline', async () => {
@@ -127,8 +128,8 @@ test.describe.serial('7. Offline Sync', () => {
await popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientBPassword456!');
await popup.click(ButtonSelectors.SAVE);
- // Wait for save to complete (in offline mode, this saves locally)
- await popup.waitForTimeout(500);
+ // Wait for save to complete by waiting for credential to appear
+ await waitForCredentialSaved(popup, credentialNameB);
await popup.screenshot({ path: 'tests/screenshots/7.4-client-b-offline-credential-saved.png' });
@@ -144,21 +145,20 @@ test.describe.serial('7. Offline Sync', () => {
// Navigate to Settings tab via bottom navigation
await popup.getByRole('button', { name: 'Settings' }).click();
- await popup.waitForTimeout(100);
+
+ // Wait for settings page to load
+ await waitForSettingsPage(popup);
await popup.screenshot({ path: 'tests/screenshots/7.5-client-b-settings-page.png' });
// Click the lock button (has title="Lock")
const lockButton = popup.locator('button[title="Lock"]');
- await expect(lockButton).toBeVisible({ timeout: 5000 });
await lockButton.click();
- await popup.waitForTimeout(500);
+ // Wait for unlock page to appear
+ await waitForUnlockPage(popup);
await popup.screenshot({ path: 'tests/screenshots/7.5-client-b-vault-locked.png' });
-
- // Verify we're on the unlock page
- await expect(popup.locator('input#password')).toBeVisible({ timeout: 5000 });
});
test('7.6 Client B unlocks vault while still offline', async () => {
@@ -169,8 +169,8 @@ test.describe.serial('7. Offline Sync', () => {
await popup.fill('input#password', sharedTestUser.password);
await popup.click('button:has-text("Unlock")');
- // Wait for unlock and navigation to complete
- await popup.waitForTimeout(2000);
+ // Wait for vault UI to be ready after unlock
+ await waitForVaultReady(popup, 30000);
await popup.screenshot({ path: 'tests/screenshots/7.6-client-b-after-unlock.png' });
@@ -193,8 +193,8 @@ test.describe.serial('7. Offline Sync', () => {
// Navigate to root to trigger a sync
await navigateToRoot(popup);
- // Wait for sync to complete
- await popup.waitForTimeout(2000);
+ // Wait for vault to be ready (sync happens automatically)
+ await waitForVaultReady(popup, 30000);
await popup.screenshot({ path: 'tests/screenshots/7.7-client-b-back-online.png' });
@@ -202,16 +202,13 @@ test.describe.serial('7. Offline Sync', () => {
// - The credential it created offline (uploaded during sync)
// - The credential Client A created (downloaded during sync)
await navigateToVault(popup);
- await popup.waitForTimeout(500);
-
- await popup.screenshot({ path: 'tests/screenshots/7.7-client-b-vault-after-sync.png' });
- // Verify Client B's offline credential is still there
+ // Wait for both credentials to appear (indicates sync completed)
await verifyCredentialExists(popup, credentialNameB);
-
- // Verify Client A's credential was downloaded during sync
await verifyCredentialExists(popup, credentialNameA);
+ await popup.screenshot({ path: 'tests/screenshots/7.7-client-b-vault-after-sync.png' });
+
// Verify total item count is 2
await verifyVaultItemCount(popup, 2);
});
@@ -222,10 +219,8 @@ test.describe.serial('7. Offline Sync', () => {
// Navigate to root to trigger a sync
await navigateToRoot(popup);
- // Wait for sync to complete
- await popup.waitForTimeout(2000);
-
- await popup.screenshot({ path: 'tests/screenshots/7.8-client-a-vault-after-sync.png' });
+ // Wait for vault to be ready
+ await waitForVaultReady(popup, 30000);
// Verify both credentials exist
await navigateToVault(popup);
@@ -236,6 +231,8 @@ test.describe.serial('7. Offline Sync', () => {
// Client B's credential (created offline, then synced)
await verifyCredentialExists(popup, credentialNameB);
+ await popup.screenshot({ path: 'tests/screenshots/7.8-client-a-vault-after-sync.png' });
+
// Verify total item count is 2
await verifyVaultItemCount(popup, 2);
diff --git a/apps/browser-extension/tests/fixtures/fixtures.ts b/apps/browser-extension/tests/fixtures/fixtures.ts
index ab4258821..ec500f8cd 100644
--- a/apps/browser-extension/tests/fixtures/fixtures.ts
+++ b/apps/browser-extension/tests/fixtures/fixtures.ts
@@ -207,8 +207,8 @@ export async function configureApiUrl(popup: Page, apiUrl: string): Promise<void
// Go back to main page
await popup.click('button#back');
- // Wait a moment for the settings to be saved
- await popup.waitForTimeout(200);
+ // Wait for the login form to be visible (indicates settings were saved and we're back)
+ await popup.waitForSelector('input[type="text"], input[type="password"]', { state: 'visible' });
}
/**
diff --git a/apps/browser-extension/tests/fixtures/helpers.ts b/apps/browser-extension/tests/fixtures/helpers.ts
index 30679f16e..251e093eb 100644
--- a/apps/browser-extension/tests/fixtures/helpers.ts
+++ b/apps/browser-extension/tests/fixtures/helpers.ts
@@ -82,7 +82,8 @@ export async function navigateToVault(popup: Page): Promise<void> {
*/
export async function clickCredential(popup: Page, credentialName: string): Promise<void> {
await popup.locator(`text=${credentialName}`).click();
- await popup.waitForTimeout(100);
+ // Wait for the credential details view to load
+ await popup.locator('button[title="Edit Credential"]').waitFor({ state: 'visible', timeout: 5000 });
}
/**
@@ -143,7 +144,8 @@ export async function navigateToRoot(popup: Page): Promise<void> {
await popup.evaluate(() => {
window.location.href = '/popup.html';
});
- await popup.waitForTimeout(100);
+ // Wait for the page to load and vault to be ready
+ await popup.waitForLoadState('domcontentloaded');
}
/**
@@ -153,7 +155,10 @@ export async function navigateToRoot(popup: Page): Promise<void> {
*/
export async function saveCredential(popup: Page): Promise<void> {
await popup.click(ButtonSelectors.SAVE);
- await popup.waitForTimeout(100);
+ // Wait for the save to complete by waiting for form to disappear or details to show
+ // The save button becomes disabled during save, so we wait for it to be enabled again
+ // or for us to navigate away from the form
+ await popup.waitForLoadState('domcontentloaded');
}
/**
@@ -195,11 +200,13 @@ export async function fillPassword(popup: Page, password: string): Promise<void>
*/
export async function setApiUrl(popup: Page, apiUrl: string): Promise<void> {
await popup.evaluate((url) => {
- // Access chrome.storage.local directly to set the API URL
- chrome.storage.local.set({ apiUrl: url });
+ return new Promise<void>((resolve) => {
+ // Access chrome.storage.local directly to set the API URL
+ chrome.storage.local.set({ apiUrl: url }, () => {
+ resolve();
+ });
+ });
}, apiUrl);
- // Small delay to allow storage to update
- await popup.waitForTimeout(100);
}
/**
@@ -249,10 +256,13 @@ export async function disableOfflineMode(popup: Page, apiUrl: string): Promise<v
*/
export async function lockVault(popup: Page): Promise<void> {
await popup.evaluate(() => {
- // Clear the encryption key from session storage via background message
- chrome.runtime.sendMessage({ type: 'LOCK_VAULT' });
+ return new Promise<void>((resolve) => {
+ // Clear the encryption key from session storage via background message
+ chrome.runtime.sendMessage({ type: 'LOCK_VAULT' }, () => {
+ resolve();
+ });
+ });
});
- await popup.waitForTimeout(100);
}
/**
@@ -314,6 +324,101 @@ export async function unlockVault(popup: Page, password: string): Promise<void>
await popup.fill('input#password', password);
// Click the unlock button
await popup.click('button:has-text("Unlock")');
- // Wait for the vault to load
- await popup.waitForTimeout(500);
+ // Wait for the vault UI to appear (indicates successful unlock)
+ await waitForVaultReady(popup);
+}
+
+/**
+ * Wait for the vault UI to be ready (bottom navigation visible).
+ * This indicates the app has finished loading/sync and is ready for interaction.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds (default: 10000)
+ */
+export async function waitForVaultReady(popup: Page, timeout: number = 10000): Promise<void> {
+ // Wait for the Vault button in the bottom navigation to be visible
+ await popup.locator('#nav-vault').waitFor({ state: 'visible', timeout });
+}
+
+/**
+ * Wait for a sync operation to complete.
+ * Detects sync by waiting for the vault content to update or sync indicator to disappear.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds (default: 10000)
+ */
+export async function waitForSyncComplete(popup: Page, timeout: number = 10000): Promise<void> {
+ // Wait for any loading spinner to disappear (if present)
+ // The loading overlay has z-50 class - wait for it to not be visible
+ const loadingOverlay = popup.locator('.z-50');
+ await loadingOverlay.waitFor({ state: 'hidden', timeout }).catch(() => {
+ // Loading overlay might not exist, which is fine
+ });
+
+ // Also wait for the vault button to be visible and enabled
+ await waitForVaultReady(popup, timeout);
+}
+
+/**
+ * Wait for a credential to be saved and appear in the vault.
+ * This waits for navigation away from the form and the credential to be visible.
+ *
+ * @param popup - The popup page
+ * @param credentialName - The name of the credential to wait for
+ * @param timeout - Timeout in milliseconds (default: 30000)
+ */
+export async function waitForCredentialSaved(
+ popup: Page,
+ credentialName: string,
+ timeout: number = 30000
+): Promise<void> {
+ // Wait for the credential name to appear (indicates save + sync completed)
+ await expect(popup.locator(`text=${credentialName}`)).toBeVisible({ timeout });
+}
+
+/**
+ * Wait for the settings page to be visible.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds (default: 5000)
+ */
+export async function waitForSettingsPage(popup: Page, timeout: number = 5000): Promise<void> {
+ // Settings page has a lock button
+ await popup.locator('button[title="Lock"]').waitFor({ state: 'visible', timeout });
+}
+
+/**
+ * Wait for the unlock page to be visible.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds (default: 5000)
+ */
+export async function waitForUnlockPage(popup: Page, timeout: number = 5000): Promise<void> {
+ await popup.locator('input#password').waitFor({ state: 'visible', timeout });
+}
+
+/**
+ * Wait for the credential edit form to be fully loaded.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds (default: 10000)
+ */
+export async function waitForEditForm(popup: Page, timeout: number = 10000): Promise<void> {
+ await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout });
+}
+
+/**
+ * Wait for navigation to complete after a page change.
+ * This is a smart wait that looks for common UI stability indicators.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds (default: 5000)
+ */
+export async function waitForNavigation(popup: Page, timeout: number = 5000): Promise<void> {
+ // Wait for load state to be complete
+ await popup.waitForLoadState('domcontentloaded', { timeout });
+
+ // Wait for any route transition animations to complete
+ // The app uses React Router, so we wait for the content to stabilize
+ await popup.locator('#root').waitFor({ state: 'visible', timeout });
}
diff --git a/apps/browser-extension/tests/fixtures/index.ts b/apps/browser-extension/tests/fixtures/index.ts
index fb547ff58..cca03a2f6 100644
--- a/apps/browser-extension/tests/fixtures/index.ts
+++ b/apps/browser-extension/tests/fixtures/index.ts
@@ -44,6 +44,14 @@ export {
waitForOfflineIndicator,
isOfflineIndicatorVisible,
unlockVault,
+ // Smart waiting helpers
+ waitForVaultReady,
+ waitForSyncComplete,
+ waitForCredentialSaved,
+ waitForSettingsPage,
+ waitForUnlockPage,
+ waitForEditForm,
+ waitForNavigation,
} from './helpers';
// Field selectors and constants