user.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { expect, type Browser, Page } from '@playwright/test';
  2. import { type MailBuffer } from 'maildev';
  3. import * as utils from '../../global-utils';
  4. export async function createAccount(test, page: Page, user: { email: string, name: string, password: string }, mailBuffer?: MailBuffer) {
  5. await test.step(`Create user ${user.name}`, async () => {
  6. await utils.cleanLanding(page);
  7. await page.getByRole('link', { name: 'Create account' }).click();
  8. // Back to Vault create account
  9. await expect(page).toHaveTitle(/Create account | Vaultwarden Web/);
  10. await page.getByLabel(/Email address/).fill(user.email);
  11. await page.getByLabel('Name').fill(user.name);
  12. await page.getByRole('button', { name: 'Continue' }).click();
  13. // Vault finish Creation
  14. await page.getByLabel('New master password (required)', { exact: true }).fill(user.password);
  15. await page.getByLabel('Confirm new master password (').fill(user.password);
  16. await page.getByRole('button', { name: 'Create account' }).click();
  17. await utils.checkNotification(page, 'Your new account has been created')
  18. // We are now in the default vault page
  19. await expect(page).toHaveTitle('Vaults | Vaultwarden Web');
  20. await utils.checkNotification(page, 'You have been logged in!');
  21. if( mailBuffer ){
  22. await mailBuffer.expect((m) => m.subject === "Welcome");
  23. await mailBuffer.expect((m) => m.subject === "New Device Logged In From Firefox");
  24. }
  25. });
  26. }
  27. export async function logUser(test, page: Page, user: { email: string, password: string }, mailBuffer?: MailBuffer) {
  28. await test.step(`Log user ${user.email}`, async () => {
  29. await utils.cleanLanding(page);
  30. await page.getByLabel(/Email address/).fill(user.email);
  31. await page.getByRole('button', { name: 'Continue' }).click();
  32. // Unlock page
  33. await page.getByLabel('Master password').fill(user.password);
  34. await page.getByRole('button', { name: 'Log in with master password' }).click();
  35. // We are now in the default vault page
  36. await expect(page).toHaveTitle(/Vaultwarden Web/);
  37. if( mailBuffer ){
  38. await mailBuffer.expect((m) => m.subject === "New Device Logged In From Firefox");
  39. }
  40. });
  41. }