Skip to content

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

Refactor tests (#1404)

Leendert de Borstb7c2186967f5
diff --git a/apps/browser-extension/tests/e2e/01-extension-loading.spec.ts b/apps/browser-extension/tests/e2e/01-extension-loading.spec.ts
index 56514137c..2b1c6cc4e 100644
--- a/apps/browser-extension/tests/e2e/01-extension-loading.spec.ts
+++ b/apps/browser-extension/tests/e2e/01-extension-loading.spec.ts
@@ -1,44 +1,34 @@
-import type { Page } from '@playwright/test';
-
-import { test, expect, openPopup } from '../fixtures';
-
/**
* Category 1: Extension Loading (No API required)
*
* These tests verify the extension loads and renders correctly.
* They don't require an API server to be running.
- * Tests run sequentially and share the same popup page.
*/
+import { test, expect, TestClient } from '../fixtures';
+
test.describe.serial('1. Extension Loading', () => {
- let popup: Page;
+ let client: TestClient;
test.afterAll(async () => {
- // Close popup to start fresh for next test group
- await popup?.close();
+ await client?.cleanup();
});
test('1.1 should load the popup and show login form', async ({ context, extensionId }) => {
- // Open popup (first test opens it, subsequent tests reuse it)
- popup = await openPopup(context, extensionId);
+ client = await TestClient.fromContext(context, extensionId);
- // Check that React rendered (the app container should exist)
- const appContent = popup.locator('#root');
+ const appContent = client.popup.locator('#root');
await expect(appContent).toBeVisible();
- // Should show login form elements
- await expect(popup.locator('input[type="text"]')).toBeVisible();
- await expect(popup.locator('input[type="password"]')).toBeVisible();
+ await expect(client.popup.locator('input[type="text"]')).toBeVisible();
+ await expect(client.popup.locator('input[type="password"]')).toBeVisible();
- // Take a screenshot for debugging
- await popup.screenshot({ path: 'tests/screenshots/1.1-popup-loaded.png' });
+ await client.screenshot('1.1-popup-loaded.png');
});
test('1.2 should have a running service worker', async ({ context, extensionId }) => {
- // Service worker should be running
const serviceWorkers = context.serviceWorkers();
expect(serviceWorkers.length).toBeGreaterThan(0);
- // The service worker URL should match our extension
const swUrl = serviceWorkers[0].url();
expect(swUrl).toContain(extensionId);
expect(swUrl).toContain('background');
diff --git a/apps/browser-extension/tests/e2e/02-ui-navigation.spec.ts b/apps/browser-extension/tests/e2e/02-ui-navigation.spec.ts
index f91bd2741..31906fb12 100644
--- a/apps/browser-extension/tests/e2e/02-ui-navigation.spec.ts
+++ b/apps/browser-extension/tests/e2e/02-ui-navigation.spec.ts
@@ -1,57 +1,38 @@
-import type { Page } from '@playwright/test';
-
-import { test, expect, openPopup, configureApiUrl } from '../fixtures';
-
/**
* Category 2: UI Navigation (No API required)
*
* These tests verify UI navigation works without needing authentication.
* They don't require an API server to be running.
- * Tests run sequentially and share the same popup page.
*/
+import { test, expect, TestClient } from '../fixtures';
+
test.describe.serial('2. UI Navigation', () => {
- let popup: Page;
+ let client: TestClient;
test.afterAll(async () => {
- // Close popup to start fresh for next test group
- await popup?.close();
+ await client?.cleanup();
});
test('2.1 should have working settings button', async ({ context, extensionId }) => {
- // Open popup (first test opens it)
- popup = await openPopup(context, extensionId);
-
- // Click settings button
- const settingsButton = popup.locator('button#settings');
- await expect(settingsButton).toBeVisible();
- await settingsButton.click();
-
- // Should navigate to settings page
- // Check for settings-related elements (like the server selection dropdown)
- await expect(popup.locator('select')).toBeVisible();
+ client = await TestClient.fromContext(context, extensionId);
- // Take a screenshot
- await popup.screenshot({ path: 'tests/screenshots/2.1-settings-navigation.png' });
+ await client
+ .openLoginSettings()
+ .then((c) => c.screenshot('2.1-settings-navigation.png'));
- // Should have a back button
- const backButton = popup.locator('button#back');
+ const backButton = client.popup.locator('button#back');
await expect(backButton).toBeVisible();
- // Click back and verify we return to login
- await backButton.click();
- await expect(popup.locator('input[type="text"]')).toBeVisible();
+ await client.backToLogin();
+ await expect(client.popup.locator('input[type="text"]')).toBeVisible();
});
test('2.2 should allow configuring custom API URL', async ({ apiUrl }) => {
- // Reuse popup from previous test
- // Configure the API URL
- await configureApiUrl(popup, apiUrl);
+ await client.configureApiUrl(apiUrl);
- // After going back, we should still be on the login page
- await expect(popup.locator('input[type="text"]')).toBeVisible();
- await expect(popup.locator('input[type="password"]')).toBeVisible();
+ await expect(client.popup.locator('input[type="text"]')).toBeVisible();
+ await expect(client.popup.locator('input[type="password"]')).toBeVisible();
- // Take a screenshot
- await popup.screenshot({ path: 'tests/screenshots/2.2-api-configured.png' });
+ await client.screenshot('2.2-api-configured.png');
});
});
diff --git a/apps/browser-extension/tests/e2e/03-authentication.spec.ts b/apps/browser-extension/tests/e2e/03-authentication.spec.ts
index 1d9578049..020e76d0c 100644
--- a/apps/browser-extension/tests/e2e/03-authentication.spec.ts
+++ b/apps/browser-extension/tests/e2e/03-authentication.spec.ts
@@ -1,53 +1,35 @@
-import type { Page } from '@playwright/test';
-
-import { test, expect, openPopup, configureApiUrl, login, waitForLoggedIn } from '../fixtures';
-
/**
* Category 3: Authentication Flow (Requires API)
*
* These tests verify login/authentication works correctly.
* They require an API server to be running at localhost:5092.
- * Tests run sequentially and share the same popup page.
*/
+import { test, expect, TestClient } from '../fixtures';
+
test.describe.serial('3. Authentication Flow', () => {
- let popup: Page;
+ let client: TestClient;
test.afterAll(async () => {
- // Close popup to start fresh for next test group
- await popup?.close();
+ await client?.cleanup();
});
test('3.1 should display error for invalid credentials', async ({ context, extensionId, apiUrl }) => {
- // Open popup (first test opens it)
- popup = await openPopup(context, extensionId);
-
- // Configure API URL
- await configureApiUrl(popup, apiUrl);
+ client = await TestClient.fromContext(context, extensionId);
+ await client.configureApiUrl(apiUrl);
- // Try to login with invalid credentials
- await popup.fill('input[type="text"]', '[email protected]');
- await popup.fill('input[type="password"]', 'wrongpassword');
- await popup.click('button:has-text("Log in")');
+ await client
+ .attemptLogin('[email protected]', 'wrongpassword')
+ .then((c) => c.screenshot('3.1-login-failed.png'));
- // Wait for error message to appear
- await expect(popup.locator('text=Invalid username or password')).toBeVisible({ timeout: 10000 });
+ await expect(client.popup.locator('text=Invalid username or password')).toBeVisible({ timeout: 10000 });
- // Take a screenshot
- await popup.screenshot({ path: 'tests/screenshots/3.1-login-failed.png' });
-
- // Clear the form for the next test
- await popup.fill('input[type="text"]', '');
- await popup.fill('input[type="password"]', '');
+ await client.clearLoginForm();
});
test('3.2 should successfully login with valid credentials', async ({ testUser }) => {
- // Login with valid credentials
- await login(popup, testUser.username, testUser.password);
-
- // Verify we're logged in
- await waitForLoggedIn(popup);
-
- // Take a screenshot
- await popup.screenshot({ path: 'tests/screenshots/3.2-login-success.png' });
+ await client
+ .fillLoginForm(testUser.username, testUser.password)
+ .then((c) => c.submitLogin())
+ .then((c) => c.screenshot('3.2-login-success.png'));
});
});
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 62d3f0276..2da879c78 100644
--- a/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
+++ b/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
@@ -1,100 +1,42 @@
-import type { Page } from '@playwright/test';
-
-import {
- test,
- expect,
- openPopup,
- fullLoginFlow,
- waitForLoggedIn,
- navigateToVault,
- navigateToAddCredentialForm,
- verifyCredentialExists,
- waitForVaultReady,
- FieldSelectors,
- ButtonSelectors,
-} from '../fixtures';
-
/**
* Category 4: Create Credential (Requires API + Authentication)
*
* These tests verify credential creation functionality after login.
* They require an API server to be running at localhost:5092.
- * Tests run sequentially and share the same popup page (already logged in).
*/
+import { test, expect, TestClient } from '../fixtures';
+
test.describe.serial('4. Create Credential', () => {
- let popup: Page;
+ let client: TestClient;
const testCredentialName = `Test Login ${Date.now()}`;
test.afterAll(async () => {
- // Close popup to start fresh for next test group
- await popup?.close();
+ await client?.cleanup();
});
- test('4.1 should login and show vault content', async ({ context, extensionId, testUser, apiUrl }) => {
- // Open popup and login
- popup = await openPopup(context, extensionId);
- await fullLoginFlow(popup, apiUrl, testUser.username, testUser.password);
+ test('4.1 should login and show vault content', async ({ testUser, apiUrl }) => {
+ client = await TestClient.create();
+ await client.login(apiUrl, testUser.username, testUser.password);
- // Wait for the vault to load
- await waitForLoggedIn(popup);
-
- // For a new user, the vault should be empty but rendered
- const rootContent = await popup.locator('#root').textContent();
+ const rootContent = await client.popup.locator('#root').textContent();
expect(rootContent).toBeTruthy();
expect(rootContent!.length).toBeGreaterThan(0);
- // Take a screenshot
- await popup.screenshot({ path: 'tests/screenshots/4.1-vault-content.png' });
+ await client.screenshot('4.1-vault-content.png');
});
test('4.2 should create a new credential', async () => {
- // Ensure we're logged in
- await waitForLoggedIn(popup);
-
- // Navigate to the Vault tab
- await navigateToVault(popup);
-
- // Navigate to the add credential form
- await navigateToAddCredentialForm(popup);
-
- // Enter the item name
- await popup.fill(FieldSelectors.ITEM_NAME, testCredentialName);
-
- // The default type is "Login", so we can proceed
- // Click Continue/Next button
- await popup.click(ButtonSelectors.NEXT);
-
- // Wait for the add/edit form to load
- await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
-
- // Fill in credentials
- await popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
- await popup.fill(FieldSelectors.LOGIN_PASSWORD, 'TestPassword123!');
-
- // Take a screenshot of the filled form
- await popup.screenshot({ path: 'tests/screenshots/4.2-credential-form.png' });
-
- // Click Save button
- await popup.click(ButtonSelectors.SAVE);
-
- // Wait for navigation to item details page (after save)
- await verifyCredentialExists(popup, testCredentialName);
-
- // Take a screenshot of the saved credential
- await popup.screenshot({ path: 'tests/screenshots/4.2-credential-saved.png' });
+ await client
+ .goToVault()
+ .then((c) => c.createCredential(testCredentialName, '[email protected]', 'TestPassword123!'))
+ .then((c) => c.screenshot('4.2-credential-saved.png'));
});
test('4.3 should show the created credential in the vault list', async () => {
- // Navigate back to the Vault tab
- await navigateToVault(popup);
-
- // Wait for vault to be ready
- await waitForVaultReady(popup);
-
- // Verify our created credential appears in the list
- await verifyCredentialExists(popup, testCredentialName);
-
- // Take a screenshot
- await popup.screenshot({ path: 'tests/screenshots/4.3-credential-in-list.png' });
+ await client
+ .goToVault()
+ .then((c) => c.waitForVaultReady())
+ .then((c) => c.verifyCredentialExists(testCredentialName))
+ .then((c) => c.screenshot('4.3-credential-in-list.png'));
});
});
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 3eed3b5bf..7ebc7491e 100644
--- a/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
+++ b/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
@@ -1,23 +1,3 @@
-import {
- test,
- expect,
- openPopup,
- fullLoginFlow,
- waitForLoggedIn,
- createFreshContext,
- type ClientState,
- navigateToAddCredentialForm,
- fillAndSaveCredential,
- navigateToVault,
- verifyCredentialExists,
- verifyVaultItemCount,
- cleanupClients,
- waitForVaultReady,
- FieldSelectors,
- ButtonSelectors,
- waitForCredentialSaved,
-} from '../fixtures';
-
/**
* Category 5: Vault Merge (Requires API + Multi-Client Scenario)
*
@@ -31,150 +11,98 @@ import {
* 5. After merge, Client B's vault should contain both credentials
* 6. Client A syncs and should also see both credentials
*/
+import { test, expect, TestClient, FieldSelectors } from '../fixtures';
+
test.describe.serial('5. Vault Merge', () => {
- let clientA: ClientState;
- let clientB: ClientState;
+ let clientA: TestClient;
+ let clientB: TestClient;
const credentialNameA = `Client A Credential ${Date.now()}`;
const credentialNameB = `Client B Credential ${Date.now() + 1}`;
test.afterAll(async () => {
- await cleanupClients(clientA, clientB);
+ await TestClient.cleanupAll(clientA, clientB);
});
test('5.1 should setup two clients and navigate both to add credential form', async ({ testUser, apiUrl }) => {
- // Create Client A
- const contextA = await createFreshContext();
- const popupA = await openPopup(contextA.context, contextA.extensionId);
- await fullLoginFlow(popupA, apiUrl, testUser.username, testUser.password);
- await waitForLoggedIn(popupA);
- clientA = { ...contextA, popup: popupA };
-
- // Create Client B (separate browser context, same user)
- const contextB = await createFreshContext();
- const popupB = await openPopup(contextB.context, contextB.extensionId);
- await fullLoginFlow(popupB, apiUrl, testUser.username, testUser.password);
- await waitForLoggedIn(popupB);
- clientB = { ...contextB, popup: popupB };
+ clientA = await TestClient.create();
+ await clientA.login(apiUrl, testUser.username, testUser.password);
+
+ clientB = await TestClient.create();
+ await clientB.login(apiUrl, testUser.username, testUser.password);
// Navigate BOTH clients to the add credential form NOW, before either makes changes.
// This ensures both have the same vault revision (empty vault, revision 1).
- await navigateToVault(clientA.popup);
- await navigateToAddCredentialForm(clientA.popup);
+ await clientA.goToVault().then((c) => c.openAddCredentialForm());
+ await clientB.goToVault().then((c) => c.openAddCredentialForm());
- await navigateToVault(clientB.popup);
- await navigateToAddCredentialForm(clientB.popup);
-
- // Take screenshots of both clients on the add form
- await clientA.popup.screenshot({ path: 'tests/screenshots/5.1-client-a-add-form.png' });
- await clientB.popup.screenshot({ path: 'tests/screenshots/5.1-client-b-add-form.png' });
+ await clientA.screenshot('5.1-client-a-add-form.png');
+ await clientB.screenshot('5.1-client-b-add-form.png');
});
test('5.2 Client A should create a credential and sync', async () => {
- // Client A fills and saves the credential
- // At this point, both clients have revision 1 (empty vault)
- await fillAndSaveCredential(
- clientA.popup,
- credentialNameA,
- 'ClientAPassword123!'
- );
-
- // Take a screenshot of the saved credential
- await clientA.popup.screenshot({ path: 'tests/screenshots/5.2-client-a-credential-saved.png' });
-
- // Navigate back to vault list to verify
- await navigateToVault(clientA.popup);
- await verifyCredentialExists(clientA.popup, credentialNameA);
-
- // Take screenshot of Client A's vault (now has 1 credential, revision 2)
- await clientA.popup.screenshot({ path: 'tests/screenshots/5.2-client-a-vault.png' });
+ // Client A fills and saves the credential (both clients have revision 1 at this point)
+ await clientA.popup.fill('input#itemName', credentialNameA);
+ await clientA.popup.click('button:has-text("Next")');
+ await expect(clientA.popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
+ await clientA.popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
+ await clientA.popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientAPassword123!');
+ await clientA.popup.click('button:has-text("Save")');
+
+ await clientA
+ .verifyCredentialExists(credentialNameA)
+ .then((c) => c.screenshot('5.2-client-a-credential-saved.png'))
+ .then((c) => c.goToVault())
+ .then((c) => c.verifyCredentialExists(credentialNameA))
+ .then((c) => c.screenshot('5.2-client-a-vault.png'));
});
test('5.3 Client B should create a credential (triggers merge with Client A changes)', async () => {
// Client B still has stale data (revision 1, empty vault)
- // Client B fills and saves a credential
// This should trigger a merge because the server has revision 2 from Client A
-
- const popup = clientB.popup;
-
- // Enter the item name
- await popup.fill(FieldSelectors.ITEM_NAME, credentialNameB);
-
- // Click Continue/Next button
- await popup.click(ButtonSelectors.NEXT);
-
- // Wait for the add/edit form to load
- await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
-
- // Fill in credentials
- await popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
- await popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientBPassword456!');
-
- // Click Save button
- await popup.click(ButtonSelectors.SAVE);
-
- // 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' });
+ await clientB.popup.fill('input#itemName', credentialNameB);
+ await clientB.popup.click('button:has-text("Next")');
+ await expect(clientB.popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
+ await clientB.popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
+ await clientB.popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientBPassword456!');
+ await clientB.popup.click('button:has-text("Save")');
+
+ await clientB
+ .verifyCredentialExists(credentialNameB)
+ .then((c) => c.screenshot('5.3-client-b-after-save.png'));
});
test('5.4 Client B vault should contain both credentials after merge', async () => {
- const popup = clientB.popup;
-
- // Navigate back to the Vault tab
- await navigateToVault(popup);
-
- // Take a screenshot first to see what's there
- await popup.screenshot({ path: 'tests/screenshots/5.4-client-b-vault-state.png' });
-
- // Verify Client A's credential exists (from the merge/sync)
- await verifyCredentialExists(popup, credentialNameA);
+ await clientB
+ .goToVault()
+ .then((c) => c.screenshot('5.4-client-b-vault-state.png'))
+ .then((c) => c.verifyCredentialExists(credentialNameA));
- // Check if Client B's credential also exists
- // NOTE: If this fails, it indicates the merge logic isn't preserving local changes
- const clientBCredential = popup.locator(`text=${credentialNameB}`);
+ const clientBCredential = clientB.popup.locator(`text=${credentialNameB}`);
const hasBothCredentials = await clientBCredential.isVisible().catch(() => false);
if (hasBothCredentials) {
- // Both credentials exist: merge worked correctly!
- await verifyVaultItemCount(popup, 2);
+ await clientB.verifyVaultItemCount(2);
} else {
- // Only Client A's credential exists: merge logic failed
throw new Error('Merge logic failed');
}
});
test('5.5 Client A should see credentials after syncing', async () => {
- const popup = clientA.popup;
+ await clientA
+ .goToVault()
+ .then((c) => c.verifyCredentialExists(credentialNameA))
+ .then((c) => c.screenshot('5.5-client-a-vault-state.png'));
- // Navigate to the Vault tab (this should trigger a sync/refresh)
- await navigateToVault(popup);
-
- // 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' });
-
- // Check if Client B's credential also synced
- const clientBCredential = popup.locator(`text=${credentialNameB}`);
+ const clientBCredential = clientA.popup.locator(`text=${credentialNameB}`);
const hasBothCredentials = await clientBCredential.isVisible().catch(() => false);
if (hasBothCredentials) {
- // Both credentials synced - take success screenshot
- await popup.screenshot({ path: 'tests/screenshots/5.5-client-a-synced-both.png' });
-
- // Check the item count shows 2 items
- await verifyVaultItemCount(popup, 2);
+ await clientA.screenshot('5.5-client-a-synced-both.png');
+ await clientA.verifyVaultItemCount(2);
} else {
- // Only Client A's credential - Client B's was lost in merge
- await popup.screenshot({ path: 'tests/screenshots/5.5-client-a-only-own-credential.png' });
-
- // Accept current behavior
- const itemsText = popup.locator('text=/\\(1 items?\\)/');
+ await clientA.screenshot('5.5-client-a-only-own-credential.png');
+ const itemsText = clientA.popup.locator('text=/\\(1 items?\\)/');
await expect(itemsText).toBeVisible({ timeout: 5000 });
}
});
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 59b1e155e..516686126 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
@@ -1,28 +1,3 @@
-import {
- test,
- expect,
- openPopup,
- fullLoginFlow,
- waitForLoggedIn,
- createFreshContext,
- type ClientState,
- navigateToAddCredentialForm,
- fillAndSaveCredential,
- navigateToVault,
- navigateToRoot,
- clickCredential,
- openCredentialEditForm,
- verifyCredentialExists,
- getFieldValue,
- saveCredential,
- fillUsername,
- fillPassword,
- fillNotes,
- cleanupClients,
- waitForVaultReady,
- FieldSelectors,
-} from '../fixtures';
-
/**
* Category 6: Field-Level Merge (Requires API + Multi-Client Scenario)
*
@@ -40,163 +15,107 @@ import {
* 5. After merge, both username (from A) and password (from B) should be preserved
* 6. Notes should have Client B's value (last writer wins)
*/
+import { test, expect, TestClient, FieldSelectors } from '../fixtures';
+
test.describe.serial('6. Field-Level Merge', () => {
- let clientA: ClientState;
- let clientB: ClientState;
+ let clientA: TestClient;
+ let clientB: TestClient;
const credentialName = `Field Merge Test ${Date.now()}`;
const originalUsername = '[email protected]';
const originalPassword = 'OriginalPassword123!';
- // Values for field-level merge test
const clientAUsername = '[email protected]';
const clientANotes = 'Notes modified by Client A';
const clientBPassword = 'ClientBModifiedPassword789!';
const clientBNotes = 'Notes modified by Client B - this should win';
test.afterAll(async () => {
- await cleanupClients(clientA, clientB);
+ await TestClient.cleanupAll(clientA, clientB);
});
test('6.1 Setup: Both clients login and Client A creates a credential', async ({ testUser, apiUrl }) => {
- // Create Client A
- const contextA = await createFreshContext();
- const popupA = await openPopup(contextA.context, contextA.extensionId);
- await fullLoginFlow(popupA, apiUrl, testUser.username, testUser.password);
- await waitForLoggedIn(popupA);
- clientA = { ...contextA, popup: popupA };
-
- // Create Client B
- const contextB = await createFreshContext();
- const popupB = await openPopup(contextB.context, contextB.extensionId);
- await fullLoginFlow(popupB, apiUrl, testUser.username, testUser.password);
- await waitForLoggedIn(popupB);
- clientB = { ...contextB, popup: popupB };
-
- // Client A creates the credential
- await navigateToVault(clientA.popup);
- await navigateToAddCredentialForm(clientA.popup);
- await fillAndSaveCredential(clientA.popup, credentialName, originalUsername, originalPassword);
-
- await clientA.popup.screenshot({ path: 'tests/screenshots/6.1-client-a-credential-created.png' });
- });
+ clientA = await TestClient.create();
+ await clientA.login(apiUrl, testUser.username, testUser.password);
- test('6.2 Both clients sync and verify credential exists', async () => {
- // Client A navigates to vault and waits for sync
- await navigateToVault(clientA.popup);
+ clientB = await TestClient.create();
+ await clientB.login(apiUrl, testUser.username, testUser.password);
- // Take screenshot to debug what's visible
- await clientA.popup.screenshot({ path: 'tests/screenshots/6.2-client-a-vault.png' });
- await verifyCredentialExists(clientA.popup, credentialName);
+ await clientA
+ .goToVault()
+ .then((c) => c.createCredential(credentialName, originalUsername, originalPassword))
+ .then((c) => c.screenshot('6.1-client-a-credential-created.png'));
+ });
- // 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);
+ test('6.2 Both clients sync and verify credential exists', async () => {
+ await clientA
+ .goToVault()
+ .then((c) => c.screenshot('6.2-client-a-vault.png'))
+ .then((c) => c.verifyCredentialExists(credentialName));
+
+ await clientB
+ .triggerSync()
+ .then((c) => c.verifyCredentialExists(credentialName));
});
test('6.3 Client A edits credential (username and notes) and saves', async () => {
- const popup = clientA.popup;
-
- // Click on the credential to open details
- await clickCredential(popup, credentialName);
-
- // Open edit form
- await openCredentialEditForm(popup);
-
- // Modify username and notes
- await fillUsername(popup, clientAUsername);
- await fillNotes(popup, clientANotes);
-
- await popup.screenshot({ path: 'tests/screenshots/6.3-client-a-before-save.png' });
-
- // Save the credential (saveCredential now waits for completion)
- await saveCredential(popup);
-
- await popup.screenshot({ path: 'tests/screenshots/6.3-client-a-after-save.png' });
+ await clientA
+ .clickCredential(credentialName)
+ .then((c) => c.openEditForm())
+ .then((c) => c.fillUsername(clientAUsername))
+ .then((c) => c.fillNotes(clientANotes))
+ .then((c) => c.screenshot('6.3-client-a-before-save.png'))
+ .then((c) => c.saveCredential())
+ .then((c) => c.screenshot('6.3-client-a-after-save.png'));
});
test('6.4 Client B edits same credential (password and notes) with stale data', async () => {
- const popup = clientB.popup;
-
- // Client B has stale data - click on credential to open details
- await clickCredential(popup, credentialName);
-
- await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-stale-details.png' });
-
- // Open edit form
- await openCredentialEditForm(popup);
-
- await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-stale-form.png' });
-
- // Modify password and notes (different value than Client A)
- await fillPassword(popup, clientBPassword);
- await fillNotes(popup, clientBNotes);
-
- await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-before-save.png' });
-
- // Save the credential - this should trigger a merge
- await saveCredential(popup);
-
- await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-after-save.png' });
+ await clientB
+ .clickCredential(credentialName)
+ .then((c) => c.screenshot('6.4-client-b-stale-details.png'))
+ .then((c) => c.openEditForm())
+ .then((c) => c.screenshot('6.4-client-b-stale-form.png'))
+ .then((c) => c.fillPassword(clientBPassword))
+ .then((c) => c.fillNotes(clientBNotes))
+ .then((c) => c.screenshot('6.4-client-b-before-save.png'))
+ .then((c) => c.saveCredential())
+ .then((c) => c.screenshot('6.4-client-b-after-save.png'));
});
test('6.5 Client B verifies field-level merge result', async () => {
- const popup = clientB.popup;
-
- // Navigate to vault
- await navigateToVault(popup);
+ await clientB
+ .goToVault()
+ .then((c) => c.clickCredential(credentialName))
+ .then((c) => c.openEditForm())
+ .then((c) => c.screenshot('6.5-client-b-merged-form.png'));
- // Click on credential to view merged details
- await clickCredential(popup, credentialName);
-
- // Open edit form to see the actual field values
- await openCredentialEditForm(popup);
-
- await popup.screenshot({ path: 'tests/screenshots/6.5-client-b-merged-form.png' });
-
- // Verify username has Client A's value (preserved from earlier edit)
- const usernameValue = await getFieldValue(popup, FieldSelectors.LOGIN_USERNAME);
+ const usernameValue = await clientB.getFieldValue(FieldSelectors.LOGIN_USERNAME);
expect(usernameValue).toBe(clientAUsername);
- // Verify password has Client B's value (preserved from this client's edit)
- const passwordValue = await getFieldValue(popup, FieldSelectors.LOGIN_PASSWORD);
+ const passwordValue = await clientB.getFieldValue(FieldSelectors.LOGIN_PASSWORD);
expect(passwordValue).toBe(clientBPassword);
- // Verify notes has Client B's value (last writer wins)
- const notesValue = await getFieldValue(popup, FieldSelectors.LOGIN_NOTES);
+ const notesValue = await clientB.getFieldValue(FieldSelectors.LOGIN_NOTES);
expect(notesValue).toBe(clientBNotes);
- // Navigate back
- await popup.goBack();
- // Wait for the credential list to be visible
- await verifyCredentialExists(popup, credentialName);
+ await clientB.popup.goBack();
+ await clientB.verifyCredentialExists(credentialName);
});
test('6.6 Client A syncs and verifies merged credential', async () => {
- const popup = clientA.popup;
-
- // Navigate to root so it will sync and see the merged credential
- await navigateToRoot(popup);
-
- // Click on credential to view synced details
- await clickCredential(popup, credentialName);
-
- // Open edit form to verify the actual field values
- await openCredentialEditForm(popup);
-
- await popup.screenshot({ path: 'tests/screenshots/6.6-client-a-synced-form.png' });
+ await clientA
+ .triggerSync()
+ .then((c) => c.clickCredential(credentialName))
+ .then((c) => c.openEditForm())
+ .then((c) => c.screenshot('6.6-client-a-synced-form.png'));
- // Verify username has Client A's value (our original edit)
- const usernameValue = await getFieldValue(popup, FieldSelectors.LOGIN_USERNAME);
+ const usernameValue = await clientA.getFieldValue(FieldSelectors.LOGIN_USERNAME);
expect(usernameValue).toBe(clientAUsername);
- // Verify password has Client B's value (merged from other client)
- const passwordValue = await getFieldValue(popup, FieldSelectors.LOGIN_PASSWORD);
+ const passwordValue = await clientA.getFieldValue(FieldSelectors.LOGIN_PASSWORD);
expect(passwordValue).toBe(clientBPassword);
- // Verify notes has Client B's value (last writer wins)
- const notesValue = await getFieldValue(popup, FieldSelectors.LOGIN_NOTES);
+ const notesValue = await clientA.getFieldValue(FieldSelectors.LOGIN_NOTES);
expect(notesValue).toBe(clientBNotes);
});
});
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 e332936a7..670cebe4c 100644
--- a/apps/browser-extension/tests/e2e/07-offline-sync.spec.ts
+++ b/apps/browser-extension/tests/e2e/07-offline-sync.spec.ts
@@ -1,29 +1,3 @@
-import {
- test,
- expect,
- openPopup,
- fullLoginFlow,
- waitForLoggedIn,
- createFreshContext,
- type ClientState,
- navigateToAddCredentialForm,
- fillAndSaveCredential,
- navigateToVault,
- navigateToRoot,
- verifyCredentialExists,
- verifyVaultItemCount,
- cleanupClients,
- enableOfflineMode,
- disableOfflineMode,
- waitForOfflineIndicator,
- waitForSettingsPage,
- waitForUnlockPage,
- waitForVaultReady,
- waitForCredentialSaved,
- FieldSelectors,
- ButtonSelectors,
-} from '../fixtures';
-
/**
* Category 7: Offline Sync (Requires API + Multi-Client Scenario)
*
@@ -40,202 +14,108 @@ import {
* 8. Client B navigates to root to trigger sync (should merge local changes with server)
* 9. Client A syncs and verifies both credentials are present
*/
+import { test, expect, TestClient, FieldSelectors } from '../fixtures';
+
test.describe.serial('7. Offline Sync', () => {
- let clientA: ClientState;
- let clientB: ClientState;
- let originalApiUrl: string | null = null;
+ let clientA: TestClient;
+ let clientB: TestClient;
+ let originalApiUrl: string;
let sharedTestUser: { username: string; password: string };
const credentialNameA = `Online Client A ${Date.now()}`;
const credentialNameB = `Offline Client B ${Date.now() + 1}`;
test.afterAll(async () => {
- await cleanupClients(clientA, clientB);
+ await TestClient.cleanupAll(clientA, clientB);
});
test('7.1 Setup: Both clients login to the same account', async ({ testUser, apiUrl }) => {
- // Store the testUser for use in later tests (fixture creates new user each time)
sharedTestUser = { username: testUser.username, password: testUser.password };
-
- // Create Client A (will stay online)
- const contextA = await createFreshContext();
- const popupA = await openPopup(contextA.context, contextA.extensionId);
- await fullLoginFlow(popupA, apiUrl, sharedTestUser.username, sharedTestUser.password);
- await waitForLoggedIn(popupA);
- clientA = { ...contextA, popup: popupA };
-
- // Create Client B (will go offline later)
- const contextB = await createFreshContext();
- const popupB = await openPopup(contextB.context, contextB.extensionId);
- await fullLoginFlow(popupB, apiUrl, sharedTestUser.username, sharedTestUser.password);
- await waitForLoggedIn(popupB);
- clientB = { ...contextB, popup: popupB };
-
- // Store the original API URL for later restoration
originalApiUrl = apiUrl;
- await clientA.popup.screenshot({ path: 'tests/screenshots/7.1-client-a-logged-in.png' });
- await clientB.popup.screenshot({ path: 'tests/screenshots/7.1-client-b-logged-in.png' });
+ clientA = await TestClient.create();
+ await clientA.login(apiUrl, testUser.username, testUser.password);
+
+ clientB = await TestClient.create();
+ await clientB.login(apiUrl, testUser.username, testUser.password);
+
+ await clientA.screenshot('7.1-client-a-logged-in.png');
+ await clientB.screenshot('7.1-client-b-logged-in.png');
});
test('7.2 Client A creates a credential while online', async () => {
- // Client A creates a credential (online, syncs immediately)
- await navigateToVault(clientA.popup);
- await navigateToAddCredentialForm(clientA.popup);
- await fillAndSaveCredential(
- clientA.popup,
- credentialNameA,
- 'ClientAPassword123!'
- );
-
- // Verify credential was saved
- await navigateToVault(clientA.popup);
- await verifyCredentialExists(clientA.popup, credentialNameA);
-
- await clientA.popup.screenshot({ path: 'tests/screenshots/7.2-client-a-credential-created.png' });
+ await clientA
+ .goToVault()
+ .then((c) => c.createCredential(credentialNameA, '[email protected]', 'ClientAPassword123!'))
+ .then((c) => c.goToVault())
+ .then((c) => c.verifyCredentialExists(credentialNameA))
+ .then((c) => c.screenshot('7.2-client-a-credential-created.png'));
});
test('7.3 Client B goes offline', async () => {
- const popup = clientB.popup;
-
- // Put Client B into offline mode by setting an invalid API URL
- await enableOfflineMode(popup);
-
- // Navigate to root to trigger the offline detection
- await navigateToRoot(popup);
-
- // 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' });
+ await clientB
+ .enableOfflineMode()
+ .then((c) => c.triggerSync())
+ .then((c) => c.waitForOffline())
+ .then((c) => c.screenshot('7.3-client-b-offline-mode.png'));
});
test('7.4 Client B creates a credential while offline', async () => {
- const popup = clientB.popup;
-
- // Navigate to vault and create a credential while offline
- await navigateToVault(popup);
- await navigateToAddCredentialForm(popup);
-
- // Fill and save the credential
- // Note: In offline mode, this should be saved locally with hasPendingSync=true
- await popup.fill(FieldSelectors.ITEM_NAME, credentialNameB);
- await popup.click(ButtonSelectors.NEXT);
- await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
- await popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
- await popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientBPassword456!');
- await popup.click(ButtonSelectors.SAVE);
-
- // 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' });
-
- // Navigate to vault to verify the credential exists locally
- await navigateToVault(popup);
- await verifyCredentialExists(popup, credentialNameB);
-
- await popup.screenshot({ path: 'tests/screenshots/7.4-client-b-offline-credential-in-list.png' });
+ await clientB.goToVault();
+ await clientB.popup.locator('[title="Add new item"]').click();
+ await expect(clientB.popup.locator('input#itemName')).toBeVisible();
+ await clientB.popup.fill('input#itemName', credentialNameB);
+ await clientB.popup.click('button:has-text("Next")');
+ await expect(clientB.popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
+ await clientB.popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
+ await clientB.popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientBPassword456!');
+ await clientB.popup.click('button:has-text("Save")');
+
+ await clientB
+ .verifyCredentialExists(credentialNameB)
+ .then((c) => c.screenshot('7.4-client-b-offline-credential-saved.png'));
+
+ await clientB
+ .goToVault()
+ .then((c) => c.verifyCredentialExists(credentialNameB))
+ .then((c) => c.screenshot('7.4-client-b-offline-credential-in-list.png'));
});
test('7.5 Client B locks vault while offline', async () => {
- const popup = clientB.popup;
-
- // Navigate to Settings tab via bottom navigation
- await popup.getByRole('button', { name: 'Settings' }).click();
-
- // 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 lockButton.click();
-
- // Wait for unlock page to appear
- await waitForUnlockPage(popup);
-
- await popup.screenshot({ path: 'tests/screenshots/7.5-client-b-vault-locked.png' });
+ await clientB
+ .lockVault()
+ .then((c) => c.screenshot('7.5-client-b-vault-locked.png'));
});
test('7.6 Client B unlocks vault while still offline', async () => {
- const popup = clientB.popup;
-
- // Unlock the vault with the master password (use stored user from test 7.1)
- // In offline mode, this should work using stored encryption params
- await popup.fill('input#password', sharedTestUser.password);
- await popup.click('button:has-text("Unlock")');
-
- // 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' });
-
- // After unlock, verify we can see our credential
- // The extension should still be in offline mode
- await navigateToVault(popup);
- await verifyCredentialExists(popup, credentialNameB);
-
- await popup.screenshot({ path: 'tests/screenshots/7.6-client-b-offline-vault-unlocked.png' });
+ await clientB
+ .unlockVault(sharedTestUser.password)
+ .then((c) => c.screenshot('7.6-client-b-after-unlock.png'))
+ .then((c) => c.goToVault())
+ .then((c) => c.verifyCredentialExists(credentialNameB))
+ .then((c) => c.screenshot('7.6-client-b-offline-vault-unlocked.png'));
});
test('7.7 Client B goes back online and triggers sync', async () => {
- const popup = clientB.popup;
-
- // Restore the valid API URL to go back online
- if (originalApiUrl) {
- await disableOfflineMode(popup, originalApiUrl);
- }
-
- // Navigate to root to trigger a sync
- await navigateToRoot(popup);
-
- // 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' });
-
- // After coming back online and syncing, Client B should have both credentials:
- // - The credential it created offline (uploaded during sync)
- // - The credential Client A created (downloaded during sync)
- await navigateToVault(popup);
-
- // Wait for both credentials to appear (indicates sync completed)
- await verifyCredentialExists(popup, credentialNameB);
- 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);
+ await clientB
+ .disableOfflineMode(originalApiUrl)
+ .then((c) => c.triggerSync())
+ .then((c) => c.screenshot('7.7-client-b-back-online.png'))
+ .then((c) => c.goToVault())
+ .then((c) => c.verifyCredentialExists(credentialNameB))
+ .then((c) => c.verifyCredentialExists(credentialNameA))
+ .then((c) => c.screenshot('7.7-client-b-vault-after-sync.png'))
+ .then((c) => c.verifyVaultItemCount(2));
});
test('7.8 Client A syncs and verifies both credentials are present', async () => {
- const popup = clientA.popup;
-
- // Navigate to root to trigger a sync
- await navigateToRoot(popup);
-
- // Wait for vault to be ready
- await waitForVaultReady(popup, 30000);
-
- // Verify both credentials exist
- await navigateToVault(popup);
-
- // Client A's original credential
- await verifyCredentialExists(popup, credentialNameA);
-
- // 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);
-
- await popup.screenshot({ path: 'tests/screenshots/7.8-client-a-both-credentials.png' });
+ await clientA
+ .triggerSync()
+ .then((c) => c.goToVault())
+ .then((c) => c.verifyCredentialExists(credentialNameA))
+ .then((c) => c.verifyCredentialExists(credentialNameB))
+ .then((c) => c.screenshot('7.8-client-a-vault-after-sync.png'))
+ .then((c) => c.verifyVaultItemCount(2))
+ .then((c) => c.screenshot('7.8-client-a-both-credentials.png'));
});
});
diff --git a/apps/browser-extension/tests/fixtures/TestClient.ts b/apps/browser-extension/tests/fixtures/TestClient.ts
new file mode 100644
index 000000000..fdc2efa51
--- /dev/null
+++ b/apps/browser-extension/tests/fixtures/TestClient.ts
@@ -0,0 +1,402 @@
+/**
+ * TestClient - A fluent API wrapper for browser extension E2E testing.
+
+ * Example usage:
+ * ```typescript
+ * const client = await TestClient.create();
+ * await client
+ * .login(apiUrl, username, password)
+ * .createCredential('My Login', '[email protected]', 'password123')
+ * .verifyCredentialExists('My Login');
+ * ```
+ */
+import type { BrowserContext, Page } from '@playwright/test';
+import { chromium } from '@playwright/test';
+import path from 'path';
+import { fileURLToPath } from 'url';
+
+import { expect } from './fixtures';
+import { FieldSelectors, ButtonSelectors } from './selectors';
+import {
+ waitForVaultReady,
+ waitForCredentialSaved,
+ waitForSettingsPage,
+ waitForUnlockPage,
+ waitForOfflineIndicator,
+ waitForLoginForm,
+ Timeouts,
+} from './waits';
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const EXTENSION_PATH = path.join(__dirname, '..', '..', 'dist', 'chrome-mv3');
+
+/**
+ * TestClient provides a fluent API for E2E testing of the browser extension.
+ */
+export class TestClient {
+ public context: BrowserContext;
+ public extensionId: string;
+ public popup: Page;
+
+ private constructor(context: BrowserContext, extensionId: string, popup: Page) {
+ this.context = context;
+ this.extensionId = extensionId;
+ this.popup = popup;
+ }
+
+ /**
+ * Create a new TestClient with a fresh browser context.
+ */
+ static async create(): Promise<TestClient> {
+ const context = await chromium.launchPersistentContext('', {
+ headless: false,
+ args: [
+ `--disable-extensions-except=${EXTENSION_PATH}`,
+ `--load-extension=${EXTENSION_PATH}`,
+ '--no-first-run',
+ '--disable-gpu',
+ ],
+ });
+
+ // Wait for service worker and get extension ID
+ let [background] = context.serviceWorkers();
+ if (!background) {
+ background = await context.waitForEvent('serviceworker');
+ }
+ const extensionId = background.url().split('/')[2];
+
+ // Open popup
+ const popup = await context.newPage();
+ await popup.goto(`chrome-extension://${extensionId}/popup.html`);
+ await popup.waitForSelector('input[type="text"], input[type="password"], button#settings', {
+ state: 'visible',
+ timeout: Timeouts.MEDIUM,
+ });
+
+ return new TestClient(context, extensionId, popup);
+ }
+
+ /**
+ * Create a TestClient from an existing browser context (for shared fixture tests).
+ */
+ static async fromContext(context: BrowserContext, extensionId: string): Promise<TestClient> {
+ const popup = await context.newPage();
+ await popup.goto(`chrome-extension://${extensionId}/popup.html`);
+ await popup.waitForSelector('input[type="text"], input[type="password"], button#settings', {
+ state: 'visible',
+ timeout: Timeouts.MEDIUM,
+ });
+ return new TestClient(context, extensionId, popup);
+ }
+
+ /**
+ * Configure the API URL for the extension.
+ */
+ async configureApiUrl(apiUrl: string): Promise<this> {
+ const settingsButton = await this.popup.waitForSelector('button#settings');
+ await settingsButton.click();
+ await this.popup.selectOption('select', ['custom']);
+ await this.popup.fill('input#custom-api-url', apiUrl);
+ await this.popup.click('button#back');
+ await waitForLoginForm(this.popup);
+ return this;
+ }
+
+ /**
+ * Open the login settings page (before authentication).
+ */
+ async openLoginSettings(): Promise<this> {
+ const settingsButton = this.popup.locator('button#settings');
+ await settingsButton.click();
+ await expect(this.popup.locator('select')).toBeVisible();
+ return this;
+ }
+
+ /**
+ * Go back from login settings to login page.
+ */
+ async backToLogin(): Promise<this> {
+ await this.popup.click('button#back');
+ await waitForLoginForm(this.popup);
+ return this;
+ }
+
+ /**
+ * Login with username and password.
+ */
+ async login(apiUrl: string, username: string, password: string): Promise<this> {
+ await this.configureApiUrl(apiUrl);
+ await this.popup.fill('input[type="text"]', username);
+ await this.popup.fill('input[type="password"]', password);
+ await this.popup.click('button:has-text("Log in")');
+ await this.popup.getByRole('button', { name: 'Vault' }).waitFor({ state: 'visible', timeout: Timeouts.LONG });
+ return this;
+ }
+
+ /**
+ * Attempt login without expecting success (for testing invalid credentials).
+ */
+ async attemptLogin(username: string, password: string): Promise<this> {
+ await this.popup.fill('input[type="text"]', username);
+ await this.popup.fill('input[type="password"]', password);
+ await this.popup.click('button:has-text("Log in")');
+ return this;
+ }
+
+ /**
+ * Clear the login form fields.
+ */
+ async clearLoginForm(): Promise<this> {
+ await this.popup.fill('input[type="text"]', '');
+ await this.popup.fill('input[type="password"]', '');
+ return this;
+ }
+
+ /**
+ * Submit login credentials (already filled in form).
+ */
+ async submitLogin(): Promise<this> {
+ await this.popup.click('button:has-text("Log in")');
+ await this.popup.getByRole('button', { name: 'Vault' }).waitFor({ state: 'visible', timeout: Timeouts.LONG });
+ return this;
+ }
+
+ /**
+ * Fill login form fields without submitting.
+ */
+ async fillLoginForm(username: string, password: string): Promise<this> {
+ await this.popup.fill('input[type="text"]', username);
+ await this.popup.fill('input[type="password"]', password);
+ return this;
+ }
+
+ /**
+ * Navigate to the vault tab.
+ */
+ async goToVault(): Promise<this> {
+ await this.popup.locator('#nav-vault').click();
+ return this;
+ }
+
+ /**
+ * Navigate to the settings tab.
+ */
+ async goToSettings(): Promise<this> {
+ await this.popup.getByRole('button', { name: 'Settings' }).click();
+ await waitForSettingsPage(this.popup);
+ return this;
+ }
+
+ /**
+ * Navigate to root to trigger a fresh sync.
+ */
+ async triggerSync(): Promise<this> {
+ await this.popup.evaluate(() => {
+ window.location.href = '/popup.html';
+ });
+ await this.popup.waitForLoadState('domcontentloaded');
+ await waitForVaultReady(this.popup, Timeouts.LONG);
+ return this;
+ }
+
+ /**
+ * Open the add credential form.
+ */
+ async openAddCredentialForm(): Promise<this> {
+ const addButton = this.popup.locator(ButtonSelectors.ADD_NEW_ITEM);
+ await expect(addButton).toBeVisible();
+ await addButton.click();
+ await expect(this.popup.locator(FieldSelectors.ITEM_NAME)).toBeVisible();
+ return this;
+ }
+
+ /**
+ * Create a new login credential.
+ */
+ async createCredential(name: string, username: string, password: string): Promise<this> {
+ await this.openAddCredentialForm();
+ await this.popup.fill(FieldSelectors.ITEM_NAME, name);
+ await this.popup.click(ButtonSelectors.NEXT);
+ await expect(this.popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: Timeouts.MEDIUM });
+ await this.popup.fill(FieldSelectors.LOGIN_USERNAME, username);
+ await this.popup.fill(FieldSelectors.LOGIN_PASSWORD, password);
+ await this.popup.click(ButtonSelectors.SAVE);
+ await waitForCredentialSaved(this.popup, name);
+ return this;
+ }
+
+ /**
+ * Click on a credential in the vault list.
+ */
+ async clickCredential(name: string): Promise<this> {
+ await this.popup.locator(`text=${name}`).click();
+ await this.popup.locator('button[title="Edit Credential"]').waitFor({ state: 'visible', timeout: Timeouts.SHORT });
+ return this;
+ }
+
+ /**
+ * Open the edit form for the currently viewed credential.
+ */
+ async openEditForm(): Promise<this> {
+ const editButton = this.popup.locator(ButtonSelectors.EDIT_CREDENTIAL);
+ await expect(editButton).toBeVisible({ timeout: Timeouts.SHORT });
+ await editButton.click();
+ await expect(this.popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: Timeouts.MEDIUM });
+ return this;
+ }
+
+ /**
+ * Fill a field in the credential form.
+ */
+ async fillField(selector: string, value: string): Promise<this> {
+ await this.popup.fill(selector, value);
+ return this;
+ }
+
+ /**
+ * Fill the username field.
+ */
+ async fillUsername(username: string): Promise<this> {
+ return this.fillField(FieldSelectors.LOGIN_USERNAME, username);
+ }
+
+ /**
+ * Fill the password field.
+ */
+ async fillPassword(password: string): Promise<this> {
+ return this.fillField(FieldSelectors.LOGIN_PASSWORD, password);
+ }
+
+ /**
+ * Fill the notes field.
+ */
+ async fillNotes(notes: string): Promise<this> {
+ return this.fillField(FieldSelectors.LOGIN_NOTES, notes);
+ }
+
+ /**
+ * Save the current credential form.
+ */
+ async saveCredential(): Promise<this> {
+ await this.popup.click(ButtonSelectors.SAVE);
+ await this.popup.waitForLoadState('domcontentloaded');
+ return this;
+ }
+
+ /**
+ * Get the value of a field in the edit form.
+ */
+ async getFieldValue(selector: string): Promise<string> {
+ return this.popup.locator(selector).inputValue();
+ }
+
+ /**
+ * Verify a credential exists in the vault list.
+ */
+ async verifyCredentialExists(name: string, timeout: number = Timeouts.MEDIUM): Promise<this> {
+ await expect(this.popup.locator(`text=${name}`)).toBeVisible({ timeout });
+ return this;
+ }
+
+ /**
+ * Verify the vault shows a specific item count.
+ */
+ async verifyVaultItemCount(count: number): Promise<this> {
+ const itemsText = this.popup.locator(`text=/\\(${count} items?\\)/`);
+ await expect(itemsText).toBeVisible({ timeout: Timeouts.SHORT });
+ return this;
+ }
+
+ /**
+ * Enable offline mode by setting an invalid API URL.
+ */
+ async enableOfflineMode(): Promise<this> {
+ await this.popup.evaluate(() => {
+ return new Promise<void>((resolve) => {
+ chrome.storage.local.set({ apiUrl: 'http://offline.invalid.localhost:9999' }, () => {
+ resolve();
+ });
+ });
+ });
+ return this;
+ }
+
+ /**
+ * Disable offline mode by restoring a valid API URL.
+ */
+ async disableOfflineMode(apiUrl: string): Promise<this> {
+ await this.popup.evaluate((url) => {
+ return new Promise<void>((resolve) => {
+ chrome.storage.local.set({ apiUrl: url }, () => {
+ resolve();
+ });
+ });
+ }, apiUrl);
+ return this;
+ }
+
+ /**
+ * Wait for offline indicator to appear.
+ */
+ async waitForOffline(timeout: number = Timeouts.MEDIUM): Promise<this> {
+ await waitForOfflineIndicator(this.popup, timeout);
+ return this;
+ }
+
+ /**
+ * Lock the vault.
+ */
+ async lockVault(): Promise<this> {
+ await this.goToSettings();
+ const lockButton = this.popup.locator('button[title="Lock"]');
+ await lockButton.click();
+ await waitForUnlockPage(this.popup);
+ return this;
+ }
+
+ /**
+ * Unlock the vault with password.
+ */
+ async unlockVault(password: string): Promise<this> {
+ await this.popup.fill('input#password', password);
+ await this.popup.click('button:has-text("Unlock")');
+ await waitForVaultReady(this.popup, Timeouts.LONG);
+ return this;
+ }
+
+ /**
+ * Take a screenshot.
+ */
+ async screenshot(filename: string): Promise<this> {
+ await this.popup.screenshot({ path: `tests/screenshots/${filename}` });
+ return this;
+ }
+
+ /**
+ * Wait for vault to be ready.
+ */
+ async waitForVaultReady(timeout: number = Timeouts.MEDIUM): Promise<this> {
+ await waitForVaultReady(this.popup, timeout);
+ return this;
+ }
+
+ /**
+ * Clean up resources (close popup and context).
+ */
+ async cleanup(): Promise<void> {
+ await this.popup?.close();
+ await this.context?.close();
+ }
+
+ /**
+ * Static helper to clean up multiple clients.
+ */
+ static async cleanupAll(...clients: (TestClient | null | undefined)[]): Promise<void> {
+ for (const client of clients) {
+ if (client) {
+ await client.cleanup();
+ }
+ }
+ }
+}
diff --git a/apps/browser-extension/tests/fixtures/helpers.ts b/apps/browser-extension/tests/fixtures/helpers.ts
index 251e093eb..9b6e5cbd8 100644
--- a/apps/browser-extension/tests/fixtures/helpers.ts
+++ b/apps/browser-extension/tests/fixtures/helpers.ts
@@ -1,424 +1,59 @@
/**
* Shared test helpers for E2E tests.
*
- * This module provides reusable helper functions for common test operations
- * like credential creation, navigation, and form filling.
- */
-import type { BrowserContext, Page } from '@playwright/test';
-
-import { expect } from './fixtures';
-import { FieldSelectors, ButtonSelectors } from './selectors';
-
-/**
- * Client state object for multi-client tests.
- */
-export type ClientState = {
- context: BrowserContext;
- extensionId: string;
- popup: Page;
-};
-
-/**
- * Navigate to the add credential form.
- * Assumes the user is already logged in and on the vault page.
- *
- * @param popup - The popup page
- */
-export async function navigateToAddCredentialForm(popup: Page): Promise<void> {
- const addButton = popup.locator(ButtonSelectors.ADD_NEW_ITEM);
- await expect(addButton).toBeVisible();
- await addButton.click();
- await expect(popup.locator(FieldSelectors.ITEM_NAME)).toBeVisible();
-}
-
-/**
- * Fill and save a login credential form.
- *
- * @param popup - The popup page
- * @param name - The credential name
- * @param username - The username for the credential
- * @param password - The password for the credential
- */
-export async function fillAndSaveCredential(
- popup: Page,
- name: string,
- username: string,
- password: string
-): Promise<void> {
- // Enter the item name
- await popup.fill(FieldSelectors.ITEM_NAME, name);
-
- // Click Continue/Next button
- await popup.click(ButtonSelectors.NEXT);
-
- // Wait for the add/edit form to load
- await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
-
- // Fill in credentials
- await popup.fill(FieldSelectors.LOGIN_USERNAME, username);
- await popup.fill(FieldSelectors.LOGIN_PASSWORD, password);
-
- // Click Save button
- await popup.click(ButtonSelectors.SAVE);
-
- // Wait for navigation to item details page (after save and sync)
- await expect(popup.locator(`text=${name}`)).toBeVisible({ timeout: 30000 });
-}
-
-/**
- * Navigate to the vault tab.
- *
- * @param popup - The popup page
- */
-export async function navigateToVault(popup: Page): Promise<void> {
- await popup.locator('#nav-vault').click();
-}
-
-/**
- * Click on a credential in the vault list by name.
- *
- * @param popup - The popup page
- * @param credentialName - The name of the credential to click
- */
-export async function clickCredential(popup: Page, credentialName: string): Promise<void> {
- await popup.locator(`text=${credentialName}`).click();
- // Wait for the credential details view to load
- await popup.locator('button[title="Edit Credential"]').waitFor({ state: 'visible', timeout: 5000 });
-}
-
-/**
- * Open the edit form for the currently viewed credential.
- *
- * @param popup - The popup page
- */
-export async function openCredentialEditForm(popup: Page): Promise<void> {
- const editButton = popup.locator(ButtonSelectors.EDIT_CREDENTIAL);
- await expect(editButton).toBeVisible({ timeout: 5000 });
- await editButton.click();
- await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
-}
-
-/**
- * Verify a credential exists in the vault list.
- *
- * @param popup - The popup page
- * @param credentialName - The name of the credential to verify
- * @param timeout - Timeout in milliseconds (default: 10000)
- */
-export async function verifyCredentialExists(
- popup: Page,
- credentialName: string,
- timeout: number = 10000
-): Promise<void> {
- await expect(popup.locator(`text=${credentialName}`)).toBeVisible({ timeout });
-}
-
-/**
- * Verify the vault shows a specific item count.
- *
- * @param popup - The popup page
- * @param count - The expected item count
- */
-export async function verifyVaultItemCount(popup: Page, count: number): Promise<void> {
- const itemsText = popup.locator(`text=/\\(${count} items?\\)/`);
- await expect(itemsText).toBeVisible({ timeout: 5000 });
-}
+ * This module provides utility functions that can be used alongside TestClient
+ * for operations that need direct page access.
+ *
+ * For most tests, prefer using the TestClient class which provides a fluent API.
+ * These helpers are primarily for edge cases or when you need to work with
+ * raw Page objects directly.
+ */
+import type { Page } from '@playwright/test';
+
+import { FieldSelectors } from './selectors';
+
+// Re-export all waits
+export {
+ waitForVaultReady,
+ waitForSyncComplete,
+ waitForCredentialSaved,
+ waitForSettingsPage,
+ waitForUnlockPage,
+ waitForEditForm,
+ waitForNavigation,
+ waitForOfflineIndicator,
+ waitForLoginForm,
+ waitForText,
+ waitFor,
+ waitForHidden,
+ isOfflineIndicatorVisible,
+ Timeouts,
+} from './waits';
/**
* Get the value of a field in the edit form.
- *
- * @param popup - The popup page
- * @param selector - The CSS selector for the field
- * @returns The field value
*/
export async function getFieldValue(popup: Page, selector: string): Promise<string> {
return popup.locator(selector).inputValue();
}
/**
- * Navigate to root popup.html to trigger a fresh sync.
- *
- * @param popup - The popup page
- */
-export async function navigateToRoot(popup: Page): Promise<void> {
- await popup.evaluate(() => {
- window.location.href = '/popup.html';
- });
- // Wait for the page to load and vault to be ready
- await popup.waitForLoadState('domcontentloaded');
-}
-
-/**
- * Save the current credential form.
- *
- * @param popup - The popup page
- */
-export async function saveCredential(popup: Page): Promise<void> {
- await popup.click(ButtonSelectors.SAVE);
- // 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');
-}
-
-/**
- * Fill the notes field in the credential form.
- *
- * @param popup - The popup page
- * @param notes - The notes text
- */
-export async function fillNotes(popup: Page, notes: string): Promise<void> {
- await popup.fill(FieldSelectors.LOGIN_NOTES, notes);
-}
-
-/**
- * Fill the username field in the credential form.
- *
- * @param popup - The popup page
- * @param username - The username
- */
-export async function fillUsername(popup: Page, username: string): Promise<void> {
- await popup.fill(FieldSelectors.LOGIN_USERNAME, username);
-}
-
-/**
- * Fill the password field in the credential form.
- *
- * @param popup - The popup page
- * @param password - The password
- */
-export async function fillPassword(popup: Page, password: string): Promise<void> {
- await popup.fill(FieldSelectors.LOGIN_PASSWORD, password);
-}
-
-/**
- * Set the API URL in the extension's local storage.
- * This can be used to simulate offline mode by setting an invalid URL.
- *
- * @param popup - The popup page
- * @param apiUrl - The API URL to set (use invalid URL like 'http://invalid.localhost:9999' for offline)
- */
-export async function setApiUrl(popup: Page, apiUrl: string): Promise<void> {
- await popup.evaluate((url) => {
- return new Promise<void>((resolve) => {
- // Access chrome.storage.local directly to set the API URL
- chrome.storage.local.set({ apiUrl: url }, () => {
- resolve();
- });
- });
- }, apiUrl);
-}
-
-/**
- * Get the current API URL from the extension's local storage.
- *
- * @param popup - The popup page
- * @returns The current API URL
+ * Get the username field value.
*/
-export async function getApiUrl(popup: Page): Promise<string | null> {
- return popup.evaluate(() => {
- return new Promise<string | null>((resolve) => {
- chrome.storage.local.get(['apiUrl'], (result) => {
- resolve(result.apiUrl ?? null);
- });
- });
- });
+export async function getUsernameValue(popup: Page): Promise<string> {
+ return getFieldValue(popup, FieldSelectors.LOGIN_USERNAME);
}
/**
- * Simulate offline mode by setting an invalid API URL.
- * This will cause all API requests to fail, triggering the extension's offline behavior.
- *
- * @param popup - The popup page
- * @returns The original API URL that was replaced (to restore later)
+ * Get the password field value.
*/
-export async function enableOfflineMode(popup: Page): Promise<string | null> {
- const originalUrl = await getApiUrl(popup);
- await setApiUrl(popup, 'http://offline.invalid.localhost:9999');
- return originalUrl;
+export async function getPasswordValue(popup: Page): Promise<string> {
+ return getFieldValue(popup, FieldSelectors.LOGIN_PASSWORD);
}
/**
- * Restore online mode by setting the API URL back to the original value.
- *
- * @param popup - The popup page
- * @param apiUrl - The API URL to restore
+ * Get the notes field value.
*/
-export async function disableOfflineMode(popup: Page, apiUrl: string): Promise<void> {
- await setApiUrl(popup, apiUrl);
-}
-
-/**
- * Lock the vault by clearing the encryption key from session storage.
- * This simulates the user locking their vault without logging out.
- *
- * @param popup - The popup page
- */
-export async function lockVault(popup: Page): Promise<void> {
- await popup.evaluate(() => {
- return new Promise<void>((resolve) => {
- // Clear the encryption key from session storage via background message
- chrome.runtime.sendMessage({ type: 'LOCK_VAULT' }, () => {
- resolve();
- });
- });
- });
-}
-
-/**
- * Clean up a client state by closing popup and context.
- *
- * @param client - The client state to clean up
- */
-export async function cleanupClient(client: ClientState | null | undefined): Promise<void> {
- if (client) {
- await client.popup?.close();
- await client.context?.close();
- }
-}
-
-/**
- * Clean up multiple clients.
- *
- * @param clients - Array of client states to clean up
- */
-export async function cleanupClients(...clients: (ClientState | null | undefined)[]): Promise<void> {
- for (const client of clients) {
- await cleanupClient(client);
- }
-}
-
-/**
- * Wait for the offline indicator to appear on the page.
- * The indicator shows "Offline" text (from t('common.offline')) with amber background styling.
- *
- * @param popup - The popup page
- * @param timeout - Timeout in milliseconds (default: 5000)
- */
-export async function waitForOfflineIndicator(popup: Page, timeout: number = 5000): Promise<void> {
- // The offline indicator has amber background (bg-amber-100 in light mode, bg-amber-900/30 in dark mode)
- // and contains the text "Offline"
- const offlineIndicator = popup.locator('div.bg-amber-100, div.bg-amber-900\\/30').filter({ hasText: 'Offline' });
- await expect(offlineIndicator).toBeVisible({ timeout });
-}
-
-/**
- * Check if the offline indicator is visible.
- *
- * @param popup - The popup page
- * @returns True if the offline indicator is visible
- */
-export async function isOfflineIndicatorVisible(popup: Page): Promise<boolean> {
- const offlineIndicator = popup.locator('div.bg-amber-100, div.bg-amber-900\\/30').filter({ hasText: 'Offline' });
- return offlineIndicator.isVisible().catch(() => false);
-}
-
-/**
- * Perform a login on the unlock screen (for locked vault).
- *
- * @param popup - The popup page
- * @param password - The master password
- */
-export async function unlockVault(popup: Page, password: string): Promise<void> {
- // Fill in the password on the unlock screen
- await popup.fill('input#password', password);
- // Click the unlock button
- await popup.click('button:has-text("Unlock")');
- // 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 });
+export async function getNotesValue(popup: Page): Promise<string> {
+ return getFieldValue(popup, FieldSelectors.LOGIN_NOTES);
}
diff --git a/apps/browser-extension/tests/fixtures/index.ts b/apps/browser-extension/tests/fixtures/index.ts
index cca03a2f6..e167f287e 100644
--- a/apps/browser-extension/tests/fixtures/index.ts
+++ b/apps/browser-extension/tests/fixtures/index.ts
@@ -2,49 +2,23 @@
* Test fixtures index.
*
* This module exports all Playwright test fixtures and helpers.
+ *
+ * Structure:
+ * - fixtures.ts: Core Playwright fixtures (test, expect, context management)
+ * - TestClient.ts: Fluent API class for writing cleaner tests (PRIMARY API)
+ * - waits.ts: Smart waiting helpers (condition-based waits)
+ * - helpers.ts: Utility functions for direct page access
+ * - selectors.ts: CSS selectors and field constants
*/
// Core fixtures
-export {
- test,
- expect,
- openPopup,
- waitForPopupReady,
- waitForLoggedIn,
- configureApiUrl,
- login,
- fullLoginFlow,
- closeCachedContext,
- createFreshContext,
-} from './fixtures';
+export { test, expect, closeCachedContext } from './fixtures';
+
+// TestClient - the primary API for writing tests
+export { TestClient } from './TestClient';
-// Shared helpers for credential operations and multi-client tests
+// Smart waiting helpers
export {
- type ClientState,
- navigateToAddCredentialForm,
- fillAndSaveCredential,
- navigateToVault,
- clickCredential,
- openCredentialEditForm,
- verifyCredentialExists,
- verifyVaultItemCount,
- getFieldValue,
- navigateToRoot,
- saveCredential,
- fillNotes,
- fillUsername,
- fillPassword,
- setApiUrl,
- getApiUrl,
- enableOfflineMode,
- disableOfflineMode,
- lockVault,
- cleanupClient,
- cleanupClients,
- waitForOfflineIndicator,
- isOfflineIndicatorVisible,
- unlockVault,
- // Smart waiting helpers
waitForVaultReady,
waitForSyncComplete,
waitForCredentialSaved,
@@ -52,6 +26,21 @@ export {
waitForUnlockPage,
waitForEditForm,
waitForNavigation,
+ waitForOfflineIndicator,
+ waitForLoginForm,
+ waitForText,
+ waitFor,
+ waitForHidden,
+ isOfflineIndicatorVisible,
+ Timeouts,
+} from './waits';
+
+// Utility helpers for direct page access
+export {
+ getFieldValue,
+ getUsernameValue,
+ getPasswordValue,
+ getNotesValue,
} from './helpers';
// Field selectors and constants
diff --git a/apps/browser-extension/tests/fixtures/waits.ts b/apps/browser-extension/tests/fixtures/waits.ts
new file mode 100644
index 000000000..806395c62
--- /dev/null
+++ b/apps/browser-extension/tests/fixtures/waits.ts
@@ -0,0 +1,168 @@
+/**
+ * Smart waiting helpers for E2E tests.
+ *
+ * This module provides condition-based waiting functions that replace
+ * fixed timeouts with intelligent waits for specific UI states.
+ */
+import type { Page, Locator } from '@playwright/test';
+
+import { expect } from './fixtures';
+import { FieldSelectors } from './selectors';
+
+/**
+ * Default timeout values for different wait scenarios.
+ */
+export const Timeouts = {
+ SHORT: 5000,
+ MEDIUM: 10000,
+ LONG: 30000,
+} as const;
+
+/**
+ * Generic wait helper that waits for a locator to be visible.
+ * This is the building block for more specific wait functions.
+ *
+ * @param locator - The Playwright locator to wait for
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitFor(locator: Locator, timeout: number = Timeouts.MEDIUM): Promise<void> {
+ await locator.waitFor({ state: 'visible', timeout });
+}
+
+/**
+ * Wait for a locator to be hidden/detached.
+ *
+ * @param locator - The Playwright locator to wait for
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitForHidden(locator: Locator, timeout: number = Timeouts.MEDIUM): Promise<void> {
+ await locator.waitFor({ state: 'hidden', timeout });
+}
+
+/**
+ * Wait for text to appear on the page.
+ *
+ * @param popup - The popup page
+ * @param text - The text to wait for
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitForText(popup: Page, text: string, timeout: number = Timeouts.MEDIUM): Promise<void> {
+ await expect(popup.locator(`text=${text}`)).toBeVisible({ timeout });
+}
+
+/**
+ * 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
+ */
+export async function waitForVaultReady(popup: Page, timeout: number = Timeouts.MEDIUM): Promise<void> {
+ 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
+ */
+export async function waitForSyncComplete(popup: Page, timeout: number = Timeouts.MEDIUM): Promise<void> {
+ // Wait for any loading spinner to disappear (if present)
+ 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.
+ *
+ * @param popup - The popup page
+ * @param credentialName - The name of the credential to wait for
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitForCredentialSaved(
+ popup: Page,
+ credentialName: string,
+ timeout: number = Timeouts.LONG
+): Promise<void> {
+ 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
+ */
+export async function waitForSettingsPage(popup: Page, timeout: number = Timeouts.SHORT): Promise<void> {
+ 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
+ */
+export async function waitForUnlockPage(popup: Page, timeout: number = Timeouts.SHORT): 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
+ */
+export async function waitForEditForm(popup: Page, timeout: number = Timeouts.MEDIUM): Promise<void> {
+ await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout });
+}
+
+/**
+ * Wait for navigation to complete after a page change.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitForNavigation(popup: Page, timeout: number = Timeouts.SHORT): Promise<void> {
+ await popup.waitForLoadState('domcontentloaded', { timeout });
+ await popup.locator('#root').waitFor({ state: 'visible', timeout });
+}
+
+/**
+ * Wait for the offline indicator to appear on the page.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitForOfflineIndicator(popup: Page, timeout: number = Timeouts.SHORT): Promise<void> {
+ const offlineIndicator = popup.locator('div.bg-amber-100, div.bg-amber-900\\/30').filter({ hasText: 'Offline' });
+ await expect(offlineIndicator).toBeVisible({ timeout });
+}
+
+/**
+ * Wait for the login form to be visible.
+ *
+ * @param popup - The popup page
+ * @param timeout - Timeout in milliseconds
+ */
+export async function waitForLoginForm(popup: Page, timeout: number = Timeouts.SHORT): Promise<void> {
+ await popup.waitForSelector('input[type="text"], input[type="password"]', { state: 'visible', timeout });
+}
+
+/**
+ * Check if the offline indicator is visible.
+ *
+ * @param popup - The popup page
+ * @returns True if the offline indicator is visible
+ */
+export async function isOfflineIndicatorVisible(popup: Page): Promise<boolean> {
+ const offlineIndicator = popup.locator('div.bg-amber-100, div.bg-amber-900\\/30').filter({ hasText: 'Offline' });
+ return offlineIndicator.isVisible().catch(() => false);
+}