1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2025-03-13 16:57:01 +01:00
vaultwarden/playwright/tests/setups/user.ts

49 Zeilen
2 KiB
TypeScript

2024-09-25 15:42:05 +02:00
import { expect, type Browser,Page } from '@playwright/test';
2025-02-11 19:47:05 +01:00
import { type MailBuffer } from 'maildev';
2024-09-25 15:42:05 +02:00
2025-02-11 19:47:05 +01:00
import * as utils from '../../global-utils';
export async function createAccount(test, page: Page, user: { email: string, name: string, password: string }, mailBuffer?: MailBuffer) {
2024-09-25 15:42:05 +02:00
await test.step('Create user', async () => {
// Landing page
await page.goto('/');
await page.getByRole('link', { name: 'Create account' }).click();
// Back to Vault create account
await expect(page).toHaveTitle(/Create account | Vaultwarden Web/);
await page.getByLabel(/Email address/).fill(user.email);
await page.getByLabel('Name').fill(user.name);
await page.getByLabel('Master password\n (required)', { exact: true }).fill(user.password);
await page.getByLabel('Re-type master password').fill(user.password);
await page.getByRole('button', { name: 'Create account' }).click();
// Back to the login page
await expect(page).toHaveTitle('Vaultwarden Web');
2025-02-11 19:47:05 +01:00
await utils.checkNotification(page, 'Your new account has been created');
2024-09-25 15:42:05 +02:00
2025-02-11 19:47:05 +01:00
if( mailBuffer ){
await expect(mailBuffer.next((m) => m.subject === "Welcome")).resolves.toBeDefined();
2024-09-25 15:42:05 +02:00
}
});
}
2025-02-11 19:47:05 +01:00
export async function logUser(test, page: Page, user: { email: string, password: string }, mailBuffer?: MailBuffer) {
2024-09-25 15:42:05 +02:00
await test.step('Log user', async () => {
// Landing page
await page.goto('/');
await page.getByLabel(/Email address/).fill(user.email);
await page.getByRole('button', { name: 'Continue' }).click();
// Unlock page
await page.getByLabel('Master password').fill(user.password);
await page.getByRole('button', { name: 'Log in with master password' }).click();
// We are now in the default vault page
await expect(page).toHaveTitle(/Vaultwarden Web/);
2025-02-11 19:47:05 +01:00
if( mailBuffer ){
await expect(mailBuffer.next((m) => m.subject === 'New Device Logged In From Firefox')).resolves.toBeDefined();
2024-09-25 15:42:05 +02:00
}
});
}