Login.ts 843 B

1234567891011121314151617181920212223242526
  1. import path from 'node:path';
  2. import { expect, type Page } from '@playwright/test';
  3. const authFile = path.resolve(__dirname, '../.auth/admin.json');
  4. export const login = async (page: Page): Promise<void> => {
  5. // Perform authentication steps. Replace these actions with your own.
  6. await page.goto('/admin');
  7. const loginForm = await page.getByTestId('login-form');
  8. if (loginForm != null) {
  9. await loginForm.getByPlaceholder('Username or E-mail').fill('admin');
  10. await loginForm.getByPlaceholder('Password').fill('adminadmin');
  11. await loginForm
  12. .locator('[type=submit]')
  13. .filter({ hasText: 'Login' })
  14. .click();
  15. }
  16. await page.waitForURL('/admin');
  17. await expect(page).toHaveTitle(/Wiki Management Homepage/);
  18. // End of authentication steps.
  19. await page.context().storageState({ path: authFile });
  20. };