disability-person-debug.spec.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import { test } from '../../utils/test-setup';
  2. import { readFileSync } from 'fs';
  3. import { join, dirname } from 'path';
  4. import { fileURLToPath } from 'url';
  5. const __filename = fileURLToPath(import.meta.url);
  6. const __dirname = dirname(__filename);
  7. const testUsers = JSON.parse(readFileSync(join(__dirname, '../../fixtures/test-users.json'), 'utf-8'));
  8. test.describe.serial('残疾人管理 - 参数错误调试测试', () => {
  9. test.beforeEach(async ({ adminLoginPage, disabilityPersonPage }) => {
  10. // 以管理员身份登录后台
  11. await adminLoginPage.goto();
  12. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  13. await adminLoginPage.expectLoginSuccess();
  14. await disabilityPersonPage.goto();
  15. });
  16. test('调试: 新增残疾人时的参数错误问题', async ({ disabilityPersonPage, page }) => {
  17. // 生成唯一的测试数据
  18. const timestamp = Date.now();
  19. const testData = {
  20. name: `调试测试_${timestamp}`,
  21. gender: '男',
  22. idCard: `11010119900101123${timestamp % 10}`,
  23. disabilityId: `5110011990010${timestamp % 10}`,
  24. disabilityType: '视力残疾',
  25. disabilityLevel: '一级',
  26. phone: `1380013800${timestamp % 10}`,
  27. idAddress: '北京市东城区测试街道1号',
  28. province: '北京市',
  29. city: '北京市'
  30. };
  31. console.log('\n========== 开始调试测试 ==========');
  32. console.log('测试数据:', JSON.stringify(testData, null, 2));
  33. // 1. 打开创建对话框
  34. console.log('\n[步骤1] 打开新增残疾人对话框...');
  35. await disabilityPersonPage.openCreateDialog();
  36. console.log('✓ 对话框已打开');
  37. // 2. 填写表单
  38. console.log('\n[步骤2] 填写表单...');
  39. await disabilityPersonPage.fillBasicForm(testData);
  40. console.log('✓ 表单已填写');
  41. // 3. 提交表单并捕获网络请求
  42. console.log('\n[步骤3] 提交表单并监听网络请求...');
  43. const result = await disabilityPersonPage.submitForm();
  44. console.log('\n========== 网络请求分析 ==========');
  45. if (result.responses.length === 0) {
  46. console.log('⚠️ 没有捕获到任何相关网络请求!');
  47. } else {
  48. result.responses.forEach((resp, index) => {
  49. console.log(`\n[请求 ${index + 1}]`);
  50. console.log(' URL:', resp.url);
  51. console.log(' 方法:', resp.method);
  52. console.log(' 状态码:', resp.status);
  53. console.log(' OK:', resp.ok);
  54. console.log(' 状态文本:', resp.statusText);
  55. if (resp.requestBody) {
  56. console.log(' 请求体:', JSON.stringify(resp.requestBody, null, 2));
  57. }
  58. if (resp.responseBody) {
  59. console.log(' 响应体:', JSON.stringify(resp.responseBody, null, 2));
  60. }
  61. // 关键检查:状态码与响应内容
  62. console.log('\n 🔍 状态码分析:');
  63. if (resp.status === 200) {
  64. console.log(' ✓ HTTP 状态码是 200 (成功)');
  65. if (resp.responseBody) {
  66. if (resp.responseBody.message) {
  67. console.log(' 响应消息:', resp.responseBody.message);
  68. }
  69. if (resp.responseBody.error) {
  70. console.log(' ⚠️ 响应包含错误信息:', resp.responseBody.error);
  71. }
  72. }
  73. } else if (resp.status === 201) {
  74. console.log(' ✓ HTTP 状态码是 201 (已创建)');
  75. } else if (resp.status >= 400) {
  76. console.log(' ✗ HTTP 错误状态码:', resp.status);
  77. }
  78. console.log('\n 响应头:', JSON.stringify(resp.responseHeaders, null, 2));
  79. });
  80. }
  81. console.log('\n========== UI 提示分析 ==========');
  82. console.log('有错误提示:', result.hasError);
  83. console.log('有成功提示:', result.hasSuccess);
  84. if (result.errorMessage) {
  85. console.log('❌ 错误消息:', result.errorMessage);
  86. }
  87. if (result.successMessage) {
  88. console.log('✅ 成功消息:', result.successMessage);
  89. }
  90. // 4. 验证数据是否真的创建成功
  91. console.log('\n[步骤4] 验证数据是否创建成功...');
  92. // 关闭对话框(如果还在)
  93. const dialogVisible = await page.locator('[role="dialog"]').isVisible().catch(() => false);
  94. if (dialogVisible) {
  95. await page.keyboard.press('Escape');
  96. await page.waitForTimeout(500);
  97. }
  98. // 刷新页面
  99. await page.reload();
  100. await page.waitForLoadState('networkidle');
  101. await disabilityPersonPage.goto();
  102. // 搜索刚创建的残疾人
  103. await disabilityPersonPage.searchByName(testData.name);
  104. await page.waitForTimeout(1000);
  105. const personExists = await disabilityPersonPage.personExists(testData.name);
  106. console.log('\n========== 最终结论 ==========');
  107. console.log('数据实际创建成功:', personExists);
  108. if (result.hasError && personExists) {
  109. console.log('\n🔴 问题确认!');
  110. console.log(' - 前端显示:创建失败(参数错误)');
  111. console.log(' - 实际情况:数据已成功创建到数据库');
  112. console.log('\n 可能原因:');
  113. console.log(' 1. 前端判断响应状态码的逻辑错误');
  114. console.log(' 2. 后端返回 200 但前端期望 201');
  115. console.log(' 3. 响应数据结构不符合前端预期');
  116. console.log(' 4. 前端错误处理逻辑将成功误判为失败');
  117. } else if (result.hasSuccess && personExists) {
  118. console.log('\n✅ 测试通过:前端显示成功,数据也创建成功');
  119. } else if (!result.hasError && !result.hasSuccess) {
  120. console.log('\n⚠️ 没有任何提示消息');
  121. }
  122. console.log('================================\n');
  123. });
  124. });