Files
his/openhis-ui-vue3/tests/e2e/specs/bug-630.spec.ts
华佗 f4ba8028fb chore: 清理 vite timestamp 缓存 + .gitignore + Bug#630 测试用例
- 删除 14 个 vite.config.js.timestamp-*.mjs 缓存文件
- .gitignore 添加 vite.config.js.timestamp* 规则
- Bug#630 Playwright 测试用例(doctor1/123456, tenantId=1)
2026-06-01 11:43:46 +08:00

107 lines
3.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from '@playwright/test';
/**
* Bug #630: [门诊医生站] 点击选择现诊患者列表报错
* 禅道信息:
* - 登录doctor1 / 123456租户=中联医院(tenantId=1)
* - 步骤:进入门诊医生站 → 点击左侧现诊患者 → 观察右侧加载
* - 期望:右侧平滑加载病历信息
* - 实际:右侧报错异常
*/
test.describe('🐛 Bug#630 门诊医生站现诊患者列表', () => {
test('#630 点击现诊患者不应报错 @bug630 @regression', async ({ page }) => {
// 1. 先访问前端获取 cookie 域名
await page.goto('http://localhost:81/');
await page.waitForLoadState('domcontentloaded');
// 2. 调用后端登录 API 获取 token
const loginResp = await page.request.post('http://localhost:18082/openhis/login', {
data: { username: 'doctor1', password: '123456', tenantId: '1', code: '', uuid: '' }
});
const loginData = await loginResp.json();
expect(loginData.code).toBe(200);
const token = loginData.token;
// 3. 设置 Cookie前端用 js-cookie 的 Admin-Token
await page.context().addCookies([{
name: 'Admin-Token',
value: token,
domain: 'localhost',
path: '/'
}]);
// 4. 导航到门诊医生站
await page.goto('http://localhost:81/clinicManagement/doctorStation');
await page.waitForLoadState('networkidle');
await page.waitForTimeout(3000);
// 截图:页面加载后
await page.screenshot({ path: 'test-results/bug-630-step1-loaded.png', fullPage: true });
// 确认不在登录页
const currentUrl = page.url();
console.log('当前 URL:', currentUrl);
const isOnLogin = currentUrl.includes('login');
if (isOnLogin) {
console.log('⚠️ 被重定向到登录页token 可能未生效');
}
// 5. 查找并点击患者 — 尝试多种选择器
const patientSelectors = [
'.patient-list-item',
'.current-patient',
'.patient-item',
'.el-table__body tr',
'.list-item',
'[class*="patient"]',
'li',
];
let clickedPatient = false;
for (const selector of patientSelectors) {
const items = page.locator(selector);
const count = await items.count();
if (count > 0) {
console.log(`找到 ${count} 个元素 (${selector}),尝试点击第一个`);
try {
await items.first().click({ timeout: 3000 });
clickedPatient = true;
console.log(`✅ 成功点击 (${selector})`);
break;
} catch {
console.log(`❌ 点击失败 (${selector})`);
}
}
}
// 6. 等待右侧加载
await page.waitForTimeout(5000);
await page.screenshot({ path: 'test-results/bug-630-step2-after-click.png', fullPage: true });
// 7. 验证没有报错弹窗
const errorPopups = page.locator('.el-message--error');
const errorCount = await errorPopups.count();
if (errorCount > 0) {
const errorText = await errorPopups.first().textContent();
console.log(`❌ 发现 ${errorCount} 个错误弹窗: ${errorText}`);
}
// 检查控制台错误
const consoleErrors: string[] = [];
page.on('console', msg => {
if (msg.type() === 'error') consoleErrors.push(msg.text());
});
await page.waitForTimeout(2000);
// 最终截图
await page.screenshot({ path: 'test-results/bug-630-final.png', fullPage: true });
// 断言
if (clickedPatient) {
expect(errorCount).toBe(0);
}
console.log(`测试结果: ${clickedPatient ? '已点击患者' : '未找到患者元素'}, 错误弹窗: ${errorCount}`);
});
});