32 lines
1008 B
TypeScript
32 lines
1008 B
TypeScript
import { test as setup, expect } from '@playwright/test';
|
|
import { LoginPage } from '../pages/LoginPage';
|
|
import { TEST_USER } from '../utils/test-data';
|
|
|
|
const authFile = 'playwright/.auth/user.json';
|
|
|
|
/**
|
|
* Setup test to authenticate user and save the session
|
|
* This will run before other tests and save the authentication state
|
|
*/
|
|
setup('authenticate', async ({ page }) => {
|
|
const loginPage = new LoginPage(page);
|
|
|
|
// Navigate to login page
|
|
await loginPage.goto();
|
|
|
|
// Perform login
|
|
await loginPage.login(TEST_USER.email, TEST_USER.password);
|
|
|
|
// Verify login success
|
|
await loginPage.verifyLoginSuccess();
|
|
|
|
// Optional: Verify that we can see user-specific elements
|
|
// For example, check for logout button or user menu
|
|
await expect(page.locator('text=/Leave|登出|帳號/i')).toBeVisible({ timeout: 10000 });
|
|
|
|
// Save signed-in state to file
|
|
await page.context().storageState({ path: authFile });
|
|
|
|
console.log('✅ Authentication successful, session saved');
|
|
});
|