Skip to content

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

Refactor e2e tests to reduce duplicate code (#1404)

Leendert de Borst47d005918160
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 9e35ab086..bc0f0110f 100644
--- a/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
+++ b/apps/browser-extension/tests/e2e/04-create-credential.spec.ts
@@ -1,6 +1,17 @@
import type { Page } from '@playwright/test';
-import { test, expect, openPopup, fullLoginFlow, waitForLoggedIn } from '../fixtures';
+import {
+ test,
+ expect,
+ openPopup,
+ fullLoginFlow,
+ waitForLoggedIn,
+ navigateToVault,
+ navigateToAddCredentialForm,
+ verifyCredentialExists,
+ FieldSelectors,
+ ButtonSelectors,
+} from '../fixtures';
/**
* Category 4: Create Credential (Requires API + Authentication)
@@ -39,43 +50,34 @@ test.describe.serial('4. Create Credential', () => {
// Ensure we're logged in
await waitForLoggedIn(popup);
- // Navigate to the Vault tab (should already be there, but click to ensure)
- await popup.getByRole('button', { name: 'Vault' }).click();
+ // Navigate to the Vault tab
+ await navigateToVault(popup);
- // Click the add button (plus icon in header)
- const addButton = popup.locator('button[title="Add new item"]');
- await expect(addButton).toBeVisible();
- await addButton.click();
-
- // Wait for the item type selector page
- await expect(popup.locator('input#itemName')).toBeVisible();
+ // Navigate to the add credential form
+ await navigateToAddCredentialForm(popup);
// Enter the item name
- await popup.fill('input#itemName', testCredentialName);
+ await popup.fill(FieldSelectors.ITEM_NAME, testCredentialName);
// The default type is "Login", so we can proceed
// Click Continue/Next button
- await popup.click('button:has-text("Next")');
+ await popup.click(ButtonSelectors.NEXT);
// Wait for the add/edit form to load
- // Field IDs use the FieldKey format: login.username, login.password
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
-
- // Fill in a test username
- await popup.fill('input#login\\.username', '[email protected]');
+ await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
- // Fill in a test password
- await popup.fill('input#login\\.password', 'TestPassword123!');
+ // 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('button:has-text("Save")');
+ await popup.click(ButtonSelectors.SAVE);
// Wait for navigation to item details page (after save)
- // The details page should show the item name
- await expect(popup.locator(`text=${testCredentialName}`)).toBeVisible({ timeout: 10000 });
+ await verifyCredentialExists(popup, testCredentialName);
// Take a screenshot of the saved credential
await popup.screenshot({ path: 'tests/screenshots/4.2-credential-saved.png' });
@@ -83,13 +85,13 @@ test.describe.serial('4. Create Credential', () => {
test('4.3 should show the created credential in the vault list', async () => {
// Navigate back to the Vault tab
- await popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(popup);
// Wait for credentials list to load
await popup.waitForTimeout(500);
// Verify our created credential appears in the list
- await expect(popup.locator(`text=${testCredentialName}`)).toBeVisible({ timeout: 10000 });
+ await verifyCredentialExists(popup, testCredentialName);
// Take a screenshot
await popup.screenshot({ path: 'tests/screenshots/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 a44d5771d..75a59236f 100644
--- a/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
+++ b/apps/browser-extension/tests/e2e/05-vault-merge.spec.ts
@@ -1,5 +1,3 @@
-import type { BrowserContext, Page } from '@playwright/test';
-
import {
test,
expect,
@@ -7,58 +5,17 @@ import {
fullLoginFlow,
waitForLoggedIn,
createFreshContext,
+ type ClientState,
+ navigateToAddCredentialForm,
+ fillAndSaveCredential,
+ navigateToVault,
+ verifyCredentialExists,
+ verifyVaultItemCount,
+ cleanupClients,
+ FieldSelectors,
+ ButtonSelectors,
} from '../fixtures';
-/**
- * Helper to navigate to add credential form without syncing vault first.
- * This is useful for testing merge scenarios where we need stale data.
- *
- * @param popup - The popup page
- */
-async function navigateToAddCredentialForm(popup: Page): Promise<void> {
- // Click the add button (assumes we're already on vault page or can click from anywhere)
- const addButton = popup.locator('button[title="Add new item"]');
- await expect(addButton).toBeVisible();
- await addButton.click();
-
- // Wait for the item type selector page
- await expect(popup.locator('input#itemName')).toBeVisible();
-}
-
-/**
- * Helper to fill and save a 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
- */
-async function fillAndSaveCredential(
- popup: Page,
- name: string,
- username: string,
- password: string
-): Promise<void> {
- // Enter the item name
- await popup.fill('input#itemName', name);
-
- // Click Continue/Next button
- await popup.click('button:has-text("Next")');
-
- // Wait for the add/edit form to load
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
-
- // Fill in credentials
- await popup.fill('input#login\\.username', username);
- await popup.fill('input#login\\.password', password);
-
- // Click Save button
- await popup.click('button:has-text("Save")');
-
- // Wait for navigation to item details page (after save and sync)
- await expect(popup.locator(`text=${name}`)).toBeVisible({ timeout: 30000 });
-}
-
/**
* Category 5: Vault Merge (Requires API + Multi-Client Scenario)
*
@@ -73,18 +30,14 @@ async function fillAndSaveCredential(
* 6. Client A syncs and should also see both credentials
*/
test.describe.serial('5. Vault Merge', () => {
- let clientA: { context: BrowserContext; extensionId: string; popup: Page };
- let clientB: { context: BrowserContext; extensionId: string; popup: Page };
+ let clientA: ClientState;
+ let clientB: ClientState;
const credentialNameA = `Client A Credential ${Date.now()}`;
const credentialNameB = `Client B Credential ${Date.now() + 1}`;
test.afterAll(async () => {
- // Clean up both browser contexts
- await clientA?.popup?.close();
- await clientA?.context?.close();
- await clientB?.popup?.close();
- await clientB?.context?.close();
+ await cleanupClients(clientA, clientB);
});
test('5.1 should setup two clients and navigate both to add credential form', async ({ testUser, apiUrl }) => {
@@ -104,10 +57,10 @@ test.describe.serial('5. Vault Merge', () => {
// 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 clientA.popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(clientA.popup);
await navigateToAddCredentialForm(clientA.popup);
- await clientB.popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(clientB.popup);
await navigateToAddCredentialForm(clientB.popup);
// Take screenshots of both clients on the add form
@@ -129,8 +82,8 @@ test.describe.serial('5. Vault Merge', () => {
await clientA.popup.screenshot({ path: 'tests/screenshots/5.2-client-a-credential-saved.png' });
// Navigate back to vault list to verify
- await clientA.popup.getByRole('button', { name: 'Vault' }).click();
- await expect(clientA.popup.locator(`text=${credentialNameA}`)).toBeVisible({ timeout: 10000 });
+ 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' });
@@ -144,20 +97,20 @@ test.describe.serial('5. Vault Merge', () => {
const popup = clientB.popup;
// Enter the item name
- await popup.fill('input#itemName', credentialNameB);
+ await popup.fill(FieldSelectors.ITEM_NAME, credentialNameB);
// Click Continue/Next button
- await popup.click('button:has-text("Next")');
+ await popup.click(ButtonSelectors.NEXT);
// Wait for the add/edit form to load
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
+ await expect(popup.locator(FieldSelectors.LOGIN_USERNAME)).toBeVisible({ timeout: 10000 });
// Fill in credentials
- await popup.fill('input#login\\.username', '[email protected]');
- await popup.fill('input#login\\.password', 'ClientBPassword456!');
+ await popup.fill(FieldSelectors.LOGIN_USERNAME, '[email protected]');
+ await popup.fill(FieldSelectors.LOGIN_PASSWORD, 'ClientBPassword456!');
// Click Save button
- await popup.click('button:has-text("Save")');
+ await popup.click(ButtonSelectors.SAVE);
// Wait for either:
// 1. Navigation to item details page (success)
@@ -173,7 +126,7 @@ test.describe.serial('5. Vault Merge', () => {
const popup = clientB.popup;
// Navigate back to the Vault tab
- await popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(popup);
// Wait for the credentials list to load
await popup.waitForTimeout(100);
@@ -182,7 +135,7 @@ test.describe.serial('5. Vault Merge', () => {
await popup.screenshot({ path: 'tests/screenshots/5.4-client-b-vault-state.png' });
// Verify Client A's credential exists (from the merge/sync)
- await expect(popup.locator(`text=${credentialNameA}`)).toBeVisible({ timeout: 10000 });
+ await verifyCredentialExists(popup, credentialNameA);
// Check if Client B's credential also exists
// NOTE: If this fails, it indicates the merge logic isn't preserving local changes
@@ -191,8 +144,7 @@ test.describe.serial('5. Vault Merge', () => {
if (hasBothCredentials) {
// Both credentials exist: merge worked correctly!
- const itemsText = popup.locator('text=/\\(2 items\\)/');
- await expect(itemsText).toBeVisible({ timeout: 5000 });
+ await verifyVaultItemCount(popup, 2);
} else {
// Only Client A's credential exists: merge logic failed
throw new Error('Merge logic failed');
@@ -203,7 +155,7 @@ test.describe.serial('5. Vault Merge', () => {
const popup = clientA.popup;
// Navigate to the Vault tab (this should trigger a sync/refresh)
- await popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(popup);
// Wait a moment for sync to complete
await popup.waitForTimeout(2000);
@@ -212,7 +164,7 @@ test.describe.serial('5. Vault Merge', () => {
await popup.screenshot({ path: 'tests/screenshots/5.5-client-a-vault-state.png' });
// Verify Client A's original credential exists
- await expect(popup.locator(`text=${credentialNameA}`)).toBeVisible({ timeout: 10000 });
+ await verifyCredentialExists(popup, credentialNameA);
// Check if Client B's credential also synced
const clientBCredential = popup.locator(`text=${credentialNameB}`);
@@ -223,8 +175,7 @@ test.describe.serial('5. Vault Merge', () => {
await popup.screenshot({ path: 'tests/screenshots/5.5-client-a-synced-both.png' });
// Check the item count shows 2 items
- const itemsText = popup.locator('text=/\\(2 items\\)/');
- await expect(itemsText).toBeVisible({ timeout: 5000 });
+ await verifyVaultItemCount(popup, 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' });
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 50422f78a..96061ecfc 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,5 +1,3 @@
-import type { BrowserContext, Page } from '@playwright/test';
-
import {
test,
expect,
@@ -7,43 +5,23 @@ import {
fullLoginFlow,
waitForLoggedIn,
createFreshContext,
+ type ClientState,
+ navigateToAddCredentialForm,
+ fillAndSaveCredential,
+ navigateToVault,
+ navigateToRoot,
+ clickCredential,
+ openCredentialEditForm,
+ verifyCredentialExists,
+ getFieldValue,
+ saveCredential,
+ fillUsername,
+ fillPassword,
+ fillNotes,
+ cleanupClients,
+ FieldSelectors,
} from '../fixtures';
-/**
- * Helper to navigate to add credential form.
- *
- * @param popup - The popup page
- */
-async function navigateToAddCredentialForm(popup: Page): Promise<void> {
- const addButton = popup.locator('button[title="Add new item"]');
- await expect(addButton).toBeVisible();
- await addButton.click();
- await expect(popup.locator('input#itemName')).toBeVisible();
-}
-
-/**
- * Helper to fill and save a 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
- */
-async function fillAndSaveCredential(
- popup: Page,
- name: string,
- username: string,
- password: string
-): Promise<void> {
- await popup.fill('input#itemName', name);
- await popup.click('button:has-text("Next")');
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
- await popup.fill('input#login\\.username', username);
- await popup.fill('input#login\\.password', password);
- await popup.click('button:has-text("Save")');
- await expect(popup.locator(`text=${name}`)).toBeVisible({ timeout: 30000 });
-}
-
/**
* Category 6: Field-Level Merge (Requires API + Multi-Client Scenario)
*
@@ -62,8 +40,8 @@ async function fillAndSaveCredential(
* 6. Notes should have Client B's value (last writer wins)
*/
test.describe.serial('6. Field-Level Merge', () => {
- let clientA: { context: BrowserContext; extensionId: string; popup: Page };
- let clientB: { context: BrowserContext; extensionId: string; popup: Page };
+ let clientA: ClientState;
+ let clientB: ClientState;
const credentialName = `Field Merge Test ${Date.now()}`;
const originalUsername = '[email protected]';
@@ -76,10 +54,7 @@ test.describe.serial('6. Field-Level Merge', () => {
const clientBNotes = 'Notes modified by Client B - this should win';
test.afterAll(async () => {
- await clientA?.popup?.close();
- await clientA?.context?.close();
- await clientB?.popup?.close();
- await clientB?.context?.close();
+ await cleanupClients(clientA, clientB);
});
test('6.1 Setup: Both clients login and Client A creates a credential', async ({ testUser, apiUrl }) => {
@@ -98,7 +73,7 @@ test.describe.serial('6. Field-Level Merge', () => {
clientB = { ...contextB, popup: popupB };
// Client A creates the credential
- await clientA.popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(clientA.popup);
await navigateToAddCredentialForm(clientA.popup);
await fillAndSaveCredential(clientA.popup, credentialName, originalUsername, originalPassword);
@@ -107,46 +82,35 @@ 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 clientA.popup.getByRole('button', { name: 'Vault' }).click();
+ 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' });
- await expect(clientA.popup.locator(`text=${credentialName}`)).toBeVisible({ timeout: 10000 });
+ await verifyCredentialExists(clientA.popup, credentialName);
// Let Client B navigate to root so it will sync and see the credential
- await clientB.popup.evaluate(() => {
- window.location.href = '/popup.html';
- });
- await clientB.popup.waitForTimeout(100);
- await expect(clientB.popup.locator(`text=${credentialName}`)).toBeVisible({ timeout: 10000 });
+ await navigateToRoot(clientB.popup);
+ await verifyCredentialExists(clientB.popup, 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 popup.locator(`text=${credentialName}`).click();
- await popup.waitForTimeout(100);
-
- // Click the edit button
- const editButton = popup.locator('button[title="Edit Credential"]');
- await expect(editButton).toBeVisible({ timeout: 5000 });
- await editButton.click();
+ await clickCredential(popup, credentialName);
- // Wait for edit form to load
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
+ // Open edit form
+ await openCredentialEditForm(popup);
- // Modify username
- await popup.fill('input#login\\.username', clientAUsername);
-
- // Modify notes
- await popup.fill('textarea#login\\.notes', clientANotes);
+ // 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' });
- // Click Save button
- await popup.click('button:has-text("Save")');
+ // Save the credential
+ await saveCredential(popup);
// Wait for save to complete
await popup.waitForTimeout(500);
@@ -158,34 +122,23 @@ test.describe.serial('6. Field-Level Merge', () => {
const popup = clientB.popup;
// Client B has stale data - click on credential to open details
- await popup.locator(`text=${credentialName}`).click();
- await popup.waitForTimeout(100);
+ await clickCredential(popup, credentialName);
await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-stale-details.png' });
- // Click the edit button
- const editButton = popup.locator('button[title="Edit Credential"]');
- await expect(editButton).toBeVisible({ timeout: 5000 });
- await editButton.click();
-
- // Wait for edit form to load
- await expect(popup.locator('input#login\\.password')).toBeVisible({ timeout: 10000 });
+ // Open edit form
+ await openCredentialEditForm(popup);
await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-stale-form.png' });
- // Modify password
- await popup.fill('input#login\\.password', clientBPassword);
-
- // Modify notes (different value than Client A)
- await popup.fill('textarea#login\\.notes', clientBNotes);
+ // 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' });
- // Click Save button - this should trigger a merge
- await popup.click('button:has-text("Save")');
-
- // Wait for save/merge to complete
- await popup.waitForTimeout(100);
+ // Save the credential - this should trigger a merge
+ await saveCredential(popup);
await popup.screenshot({ path: 'tests/screenshots/6.4-client-b-after-save.png' });
});
@@ -194,32 +147,27 @@ test.describe.serial('6. Field-Level Merge', () => {
const popup = clientB.popup;
// Navigate to vault
- await popup.getByRole('button', { name: 'Vault' }).click();
+ await navigateToVault(popup);
await popup.waitForTimeout(100);
// Click on credential to view merged details
- await popup.locator(`text=${credentialName}`).click();
- await popup.waitForTimeout(100);
-
- // Click edit to see the actual field values
- const editButton = popup.locator('button[title="Edit Credential"]');
- await expect(editButton).toBeVisible({ timeout: 5000 });
- await editButton.click();
+ await clickCredential(popup, credentialName);
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
+ // 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 popup.locator('input#login\\.username').inputValue();
+ const usernameValue = await getFieldValue(popup, FieldSelectors.LOGIN_USERNAME);
expect(usernameValue).toBe(clientAUsername);
// Verify password has Client B's value (preserved from this client's edit)
- const passwordValue = await popup.locator('input#login\\.password').inputValue();
+ const passwordValue = await getFieldValue(popup, FieldSelectors.LOGIN_PASSWORD);
expect(passwordValue).toBe(clientBPassword);
// Verify notes has Client B's value (last writer wins)
- const notesValue = await popup.locator('textarea#login\\.notes').inputValue();
+ const notesValue = await getFieldValue(popup, FieldSelectors.LOGIN_NOTES);
expect(notesValue).toBe(clientBNotes);
// Navigate back
@@ -230,34 +178,27 @@ test.describe.serial('6. Field-Level Merge', () => {
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 credential
- await popup.evaluate(() => {
- window.location.href = '/popup.html';
- });
+ // Navigate to root so it will sync and see the merged credential
+ await navigateToRoot(popup);
// Click on credential to view synced details
- await popup.locator(`text=${credentialName}`).click();
- await popup.waitForTimeout(100);
-
- // Click edit to verify the actual field values
- const editButton = popup.locator('button[title="Edit Credential"]');
- await expect(editButton).toBeVisible({ timeout: 5000 });
- await editButton.click();
+ await clickCredential(popup, credentialName);
- await expect(popup.locator('input#login\\.username')).toBeVisible({ timeout: 10000 });
+ // 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' });
// Verify username has Client A's value (our original edit)
- const usernameValue = await popup.locator('input#login\\.username').inputValue();
+ const usernameValue = await getFieldValue(popup, FieldSelectors.LOGIN_USERNAME);
expect(usernameValue).toBe(clientAUsername);
// Verify password has Client B's value (merged from other client)
- const passwordValue = await popup.locator('input#login\\.password').inputValue();
+ const passwordValue = await getFieldValue(popup, FieldSelectors.LOGIN_PASSWORD);
expect(passwordValue).toBe(clientBPassword);
// Verify notes has Client B's value (last writer wins)
- const notesValue = await popup.locator('textarea#login\\.notes').inputValue();
+ const notesValue = await getFieldValue(popup, FieldSelectors.LOGIN_NOTES);
expect(notesValue).toBe(clientBNotes);
});
});
diff --git a/apps/browser-extension/tests/fixtures/helpers.ts b/apps/browser-extension/tests/fixtures/helpers.ts
new file mode 100644
index 000000000..af8c1e52e
--- /dev/null
+++ b/apps/browser-extension/tests/fixtures/helpers.ts
@@ -0,0 +1,315 @@
+/**
+ * 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.getByRole('button', { name: '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();
+ await popup.waitForTimeout(100);
+}
+
+/**
+ * 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 });
+}
+
+/**
+ * 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';
+ });
+ await popup.waitForTimeout(100);
+}
+
+/**
+ * Save the current credential form.
+ *
+ * @param popup - The popup page
+ */
+export async function saveCredential(popup: Page): Promise<void> {
+ await popup.click(ButtonSelectors.SAVE);
+ await popup.waitForTimeout(100);
+}
+
+/**
+ * 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) => {
+ // Access chrome.storage.local directly to set the API URL
+ chrome.storage.local.set({ apiUrl: url });
+ }, apiUrl);
+ // Small delay to allow storage to update
+ await popup.waitForTimeout(100);
+}
+
+/**
+ * Get the current API URL from the extension's local storage.
+ *
+ * @param popup - The popup page
+ * @returns The current API URL
+ */
+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);
+ });
+ });
+ });
+}
+
+/**
+ * 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)
+ */
+export async function enableOfflineMode(popup: Page): Promise<string | null> {
+ const originalUrl = await getApiUrl(popup);
+ await setApiUrl(popup, 'http://offline.invalid.localhost:9999');
+ return originalUrl;
+}
+
+/**
+ * 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
+ */
+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(() => {
+ // Clear the encryption key from session storage via background message
+ chrome.runtime.sendMessage({ type: 'LOCK_VAULT' });
+ });
+ await popup.waitForTimeout(100);
+}
+
+/**
+ * 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.
+ *
+ * @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 shows "Offline Mode" text
+ await expect(popup.locator('text=Offline Mode')).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> {
+ return popup.locator('text=Offline Mode').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 to load
+ await popup.waitForTimeout(500);
+}
diff --git a/apps/browser-extension/tests/fixtures/index.ts b/apps/browser-extension/tests/fixtures/index.ts
index bc590caf7..fb547ff58 100644
--- a/apps/browser-extension/tests/fixtures/index.ts
+++ b/apps/browser-extension/tests/fixtures/index.ts
@@ -4,6 +4,7 @@
* This module exports all Playwright test fixtures and helpers.
*/
+// Core fixtures
export {
test,
expect,
@@ -16,3 +17,34 @@ export {
closeCachedContext,
createFreshContext,
} from './fixtures';
+
+// Shared helpers for credential operations and multi-client tests
+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,
+} from './helpers';
+
+// Field selectors and constants
+export { FieldKey, FieldSelectors, ButtonSelectors } from './selectors';
diff --git a/apps/browser-extension/tests/fixtures/selectors.ts b/apps/browser-extension/tests/fixtures/selectors.ts
new file mode 100644
index 000000000..9568e463a
--- /dev/null
+++ b/apps/browser-extension/tests/fixtures/selectors.ts
@@ -0,0 +1,84 @@
+/**
+ * Field selectors for E2E tests.
+ *
+ * This module provides CSS selectors for form elements based on the FieldKey
+ * constants from shared/models. This ensures tests use the same field identifiers
+ * as the application.
+ *
+ * The field key values match those defined in shared/models/src/vault/FieldKey.ts
+ * and are used as element IDs in ItemAddEdit.tsx
+ */
+
+/**
+ * Field key constants matching shared/models/src/vault/FieldKey.ts
+ * These are the raw field key values used in the application.
+ */
+export const FieldKey = {
+ LoginUsername: 'login.username',
+ LoginPassword: 'login.password',
+ LoginNotes: 'login.notes',
+ LoginUrl: 'login.url',
+ CardNumber: 'card.number',
+ CardCardholderName: 'card.cardholder_name',
+ CardExpiryMonth: 'card.expiry_month',
+ CardExpiryYear: 'card.expiry_year',
+ CardCvv: 'card.cvv',
+ CardPin: 'card.pin',
+ IdentityFirstName: 'identity.first_name',
+ IdentityLastName: 'identity.last_name',
+ IdentityEmail: 'identity.email',
+ AliasEmail: 'alias.email',
+ AliasFirstName: 'alias.first_name',
+ AliasLastName: 'alias.last_name',
+} as const;
+
+/**
+ * Escape dots in field keys for use in CSS selectors.
+ * CSS attribute selectors need dots escaped with backslash.
+ */
+function escapeFieldKey(fieldKey: string): string {
+ return fieldKey.replace(/\./g, '\\.');
+}
+
+/**
+ * CSS selectors for form input fields.
+ * These match the id attributes used in ItemAddEdit.tsx
+ */
+export const FieldSelectors = {
+ // Item name input (fixed ID, not from FieldKey)
+ ITEM_NAME: 'input#itemName',
+
+ // Login fields
+ LOGIN_USERNAME: `input#${escapeFieldKey(FieldKey.LoginUsername)}`,
+ LOGIN_PASSWORD: `input#${escapeFieldKey(FieldKey.LoginPassword)}`,
+ LOGIN_NOTES: `textarea#${escapeFieldKey(FieldKey.LoginNotes)}`,
+ LOGIN_URL: `input#${escapeFieldKey(FieldKey.LoginUrl)}`,
+
+ // Card fields
+ CARD_NUMBER: `input#${escapeFieldKey(FieldKey.CardNumber)}`,
+ CARD_CARDHOLDER_NAME: `input#${escapeFieldKey(FieldKey.CardCardholderName)}`,
+ CARD_EXPIRY_MONTH: `input#${escapeFieldKey(FieldKey.CardExpiryMonth)}`,
+ CARD_EXPIRY_YEAR: `input#${escapeFieldKey(FieldKey.CardExpiryYear)}`,
+ CARD_CVV: `input#${escapeFieldKey(FieldKey.CardCvv)}`,
+ CARD_PIN: `input#${escapeFieldKey(FieldKey.CardPin)}`,
+
+ // Identity fields
+ IDENTITY_FIRST_NAME: `input#${escapeFieldKey(FieldKey.IdentityFirstName)}`,
+ IDENTITY_LAST_NAME: `input#${escapeFieldKey(FieldKey.IdentityLastName)}`,
+ IDENTITY_EMAIL: `input#${escapeFieldKey(FieldKey.IdentityEmail)}`,
+
+ // Alias fields
+ ALIAS_EMAIL: `input#${escapeFieldKey(FieldKey.AliasEmail)}`,
+ ALIAS_FIRST_NAME: `input#${escapeFieldKey(FieldKey.AliasFirstName)}`,
+ ALIAS_LAST_NAME: `input#${escapeFieldKey(FieldKey.AliasLastName)}`,
+} as const;
+
+/**
+ * Common button selectors used across tests.
+ */
+export const ButtonSelectors = {
+ ADD_NEW_ITEM: 'button[title="Add new item"]',
+ EDIT_CREDENTIAL: 'button[title="Edit Credential"]',
+ SAVE: 'button:has-text("Save")',
+ NEXT: 'button:has-text("Next")',
+} as const;