test: Bug#630 Playwright 测试用例 — 门诊医生站现诊患者

- 登录 doctor1/123456, tenantId=1
- 通过侧边栏导航到门诊医生站
- 验证现诊患者标签可见
- 验证无错误弹窗
- 测试环境无患者数据,需手动验证点击患者场景
This commit is contained in:
2026-06-01 11:54:26 +08:00
parent 810336f989
commit d6d8864f64

View File

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