import { test, expect, Page } from '@playwright/test'; import { LoginPage } from '../pages/LoginPage'; import { TEST_USERS, TEST_URLS } from '../utils/test-data'; const ADMIN = TEST_USERS.admin; // 增加所有测试的导航超时 const NAV_TIMEOUT = 60_000; test.describe('三甲医院HIS全流程前端E2E测试', () => { let page: Page; test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); page = await context.newPage(); page.setDefaultNavigationTimeout(NAV_TIMEOUT); }); test.afterAll(async () => { await page?.context().close(); }); test('01 - 登录系统', async () => { const loginPage = new LoginPage(page); await loginPage.goto(); await loginPage.login(ADMIN.username, ADMIN.password); await loginPage.expectLoginSuccess(); await page.waitForTimeout(2000); const bodyText = await page.locator('body').innerText(); expect(bodyText.length).toBeGreaterThan(0); console.log('✅ 登录成功'); }); // 通用页面加载测试函数 const testPage = async (name: string, url: string) => { test(name, async () => { await page.goto(url, { waitUntil: 'domcontentloaded', timeout: NAV_TIMEOUT }); await page.waitForTimeout(3000); const bodyText = await page.locator('body').innerText(); // 检查不是404或错误页 expect(bodyText).not.toContain('404'); expect(bodyText).not.toContain('找不到'); expect(bodyText).not.toContain('Not Found'); // 确保页面有内容 expect(bodyText.length).toBeGreaterThan(10); console.log(`✅ ${name} - 页面加载成功`); }); }; testPage('02 - 仪表盘', TEST_URLS.dashboard); testPage('03 - 门诊挂号管理', TEST_URLS.chargeRegistration); testPage('04 - 医生工作站', TEST_URLS.doctorStation); testPage('05 - 门诊收费', TEST_URLS.chargeDetail); testPage('06 - 住院患者首页', TEST_URLS.patientHome); testPage('07 - 护理评估', TEST_URLS.nursingAssessment); testPage('08 - 手术管理', TEST_URLS.surgeryManage); testPage('09 - 麻醉管理', TEST_URLS.anesthesia); testPage('10 - 检验管理', TEST_URLS.inspection); testPage('11 - 影像管理', TEST_URLS.radiologyEnhanced); testPage('12 - 院感监测', TEST_URLS.infectionSurveillance); testPage('13 - 质量管理', TEST_URLS.qualityEnhanced); testPage('14 - 中医管理', TEST_URLS.tcmTraditional); testPage('15 - 急诊管理', TEST_URLS.emergency); testPage('16 - 药品追溯', TEST_URLS.drugTrace); testPage('17 - 经营分析', TEST_URLS.businessAnalytics); testPage('18 - 用户管理', TEST_URLS.systemUser); testPage('19 - 角色管理', TEST_URLS.systemRole); testPage('20 - 菜单管理', TEST_URLS.systemMenu); });