import { test, expect } from '@playwright/test'; import { LoginPage } from '../pages/LoginPage'; import { TEST_USERS } from '../utils/test-data'; test.describe('🔐 登录模块', () => { let loginPage: LoginPage; test.beforeEach(async ({ page }) => { loginPage = new LoginPage(page); await loginPage.goto(); }); test('TC-LOGIN-001: 管理员正常登录 @smoke', async ({ page }) => { await loginPage.login(TEST_USERS.admin.username, TEST_USERS.admin.password); await loginPage.expectLoginSuccess(); }); test('TC-LOGIN-002: 错误密码登录 @smoke', async ({ page }) => { await loginPage.login(TEST_USERS.admin.username, 'wrong_password_123'); // Check for any error indication (message, toast, or stayed on login page) const hasError = await page.locator('.el-message--error, .el-message-box, text=密码错误, text=用户名或密码错误').isVisible().catch(() => false); const stillOnLogin = page.url().includes('login') || page.url() === 'http://localhost:81/' || page.url() === 'http://localhost:81/index'; expect(hasError || stillOnLogin).toBeTruthy(); }); test('TC-LOGIN-003: 空用户名登录', async ({ page }) => { await loginPage.login('', TEST_USERS.admin.password); // Should show validation error or stay on login page const hasError = await page.locator('.el-form-item__error, .el-message--error').isVisible().catch(() => false); const stillOnLogin = page.url().includes('login') || page.url() === 'http://localhost:81/'; expect(hasError || stillOnLogin).toBeTruthy(); }); test('TC-LOGIN-004: 密码输入框可见性切换', async ({ page }) => { const passwordInput = page.locator('input[placeholder="密码"]'); await expect(passwordInput).toHaveAttribute('type', 'password'); }); });