performance.spec.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const { test, expect, request } = require('@playwright/test');
  2. const BASE_URL = 'https://ajy.danclub.cn';
  3. const API_BASE_URL = 'https://ajy.danclub.cn/api';
  4. const PERFORMANCE_THRESHOLD_MS = 200;
  5. test.describe('API性能测试', () => {
  6. test('PERF-001: 用户列表接口响应时间', async ({ request }) => {
  7. const start = Date.now();
  8. const response = await request.get(`${API_BASE_URL}/users?page=1&pageSize=10`);
  9. const duration = Date.now() - start;
  10. expect(response.status()).toBe(200);
  11. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS);
  12. });
  13. test('PERF-002: 设备列表接口响应时间', async ({ request }) => {
  14. const start = Date.now();
  15. const response = await request.get(`${API_BASE_URL}/device/page?pageNum=1&pageSize=10`);
  16. const duration = Date.now() - start;
  17. expect(response.status()).toBe(200);
  18. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS);
  19. });
  20. test('PERF-003: 穴位列表接口响应时间', async ({ request }) => {
  21. const start = Date.now();
  22. const response = await request.get(`${API_BASE_URL}/acupoint/page?pageNum=1&pageSize=10`);
  23. const duration = Date.now() - start;
  24. expect([200, 404]).toContain(response.status());
  25. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
  26. });
  27. test('PERF-004: 方案列表接口响应时间', async ({ request }) => {
  28. const start = Date.now();
  29. const response = await request.get(`${API_BASE_URL}/plan/page?pageNum=1&pageSize=10`);
  30. const duration = Date.now() - start;
  31. expect([200, 404]).toContain(response.status());
  32. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
  33. });
  34. test('PERF-005: 穴位坐标生成响应时间', async ({ request }) => {
  35. const start = Date.now();
  36. const response = await request.post(`${API_BASE_URL}/algorithm/acupoint-generate`, {
  37. data: { shoulderWidth: 42, bodyLength: 85, gender: '男', cun1: 2.2 }
  38. });
  39. const duration = Date.now() - start;
  40. expect([200, 401]).toContain(response.status());
  41. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 3);
  42. });
  43. test('PERF-006: 指寸估算响应时间', async ({ request }) => {
  44. const start = Date.now();
  45. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  46. data: { shoulderWidth: 42, bodyLength: 85, gender: '男' }
  47. });
  48. const duration = Date.now() - start;
  49. expect([200, 401]).toContain(response.status());
  50. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
  51. });
  52. test('PERF-007: 数据验证接口响应时间', async ({ request }) => {
  53. const start = Date.now();
  54. const response = await request.post(`${API_BASE_URL}/algorithm/validate`, {
  55. data: { shoulderWidth: 42, gender: '男' }
  56. });
  57. const duration = Date.now() - start;
  58. expect([200, 401]).toContain(response.status());
  59. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
  60. });
  61. test('PERF-008: 置信度计算响应时间', async ({ request }) => {
  62. const start = Date.now();
  63. const response = await request.post(`${API_BASE_URL}/algorithm/confidence`, {
  64. data: { shoulderWidth: 42, bodyLength: 85, cun1: 2.2 }
  65. });
  66. const duration = Date.now() - start;
  67. expect([200, 401]).toContain(response.status());
  68. expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
  69. });
  70. });
  71. test.describe('页面加载性能测试', () => {
  72. test('PERF-010: 用户列表页面加载时间', async ({ page }) => {
  73. await page.goto(BASE_URL);
  74. await page.waitForLoadState('networkidle');
  75. await page.getByPlaceholder('请输入用户名').fill('admin');
  76. await page.getByPlaceholder('请输入密码').fill('admin123');
  77. await page.getByRole('button', { name: '登 录' }).click();
  78. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  79. const start = Date.now();
  80. await page.goto(`${BASE_URL}/#/user/app`);
  81. await page.waitForLoadState('networkidle');
  82. const duration = Date.now() - start;
  83. expect(duration).toBeLessThan(3000);
  84. });
  85. test('PERF-011: 设备列表页面加载时间', async ({ page }) => {
  86. await page.goto(BASE_URL);
  87. await page.waitForLoadState('networkidle');
  88. await page.getByPlaceholder('请输入用户名').fill('admin');
  89. await page.getByPlaceholder('请输入密码').fill('admin123');
  90. await page.getByRole('button', { name: '登 录' }).click();
  91. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  92. const start = Date.now();
  93. await page.goto(`${BASE_URL}/#/device`);
  94. await page.waitForLoadState('networkidle');
  95. const duration = Date.now() - start;
  96. expect(duration).toBeLessThan(3000);
  97. });
  98. test('PERF-012: 穴位列表页面加载时间', async ({ page }) => {
  99. await page.goto(BASE_URL);
  100. await page.waitForLoadState('networkidle');
  101. await page.getByPlaceholder('请输入用户名').fill('admin');
  102. await page.getByPlaceholder('请输入密码').fill('admin123');
  103. await page.getByRole('button', { name: '登 录' }).click();
  104. await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
  105. const start = Date.now();
  106. await page.goto(`${BASE_URL}/#/acupoint`);
  107. await page.waitForLoadState('networkidle');
  108. const duration = Date.now() - start;
  109. expect(duration).toBeLessThan(3000);
  110. });
  111. });