| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- const { test, expect, request } = require('@playwright/test');
- const BASE_URL = 'https://ajy.danclub.cn';
- const API_BASE_URL = 'https://ajy.danclub.cn/api';
- const PERFORMANCE_THRESHOLD_MS = 200;
- test.describe('API性能测试', () => {
- test('PERF-001: 用户列表接口响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.get(`${API_BASE_URL}/users?page=1&pageSize=10`);
- const duration = Date.now() - start;
- expect(response.status()).toBe(200);
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS);
- });
- test('PERF-002: 设备列表接口响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.get(`${API_BASE_URL}/device/page?pageNum=1&pageSize=10`);
- const duration = Date.now() - start;
- expect(response.status()).toBe(200);
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS);
- });
- test('PERF-003: 穴位列表接口响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.get(`${API_BASE_URL}/acupoint/page?pageNum=1&pageSize=10`);
- const duration = Date.now() - start;
- expect([200, 404]).toContain(response.status());
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
- });
- test('PERF-004: 方案列表接口响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.get(`${API_BASE_URL}/plan/page?pageNum=1&pageSize=10`);
- const duration = Date.now() - start;
- expect([200, 404]).toContain(response.status());
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
- });
- test('PERF-005: 穴位坐标生成响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.post(`${API_BASE_URL}/algorithm/acupoint-generate`, {
- data: { shoulderWidth: 42, bodyLength: 85, gender: '男', cun1: 2.2 }
- });
- const duration = Date.now() - start;
- expect([200, 401]).toContain(response.status());
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 3);
- });
- test('PERF-006: 指寸估算响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
- data: { shoulderWidth: 42, bodyLength: 85, gender: '男' }
- });
- const duration = Date.now() - start;
- expect([200, 401]).toContain(response.status());
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
- });
- test('PERF-007: 数据验证接口响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.post(`${API_BASE_URL}/algorithm/validate`, {
- data: { shoulderWidth: 42, gender: '男' }
- });
- const duration = Date.now() - start;
- expect([200, 401]).toContain(response.status());
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
- });
- test('PERF-008: 置信度计算响应时间', async ({ request }) => {
- const start = Date.now();
- const response = await request.post(`${API_BASE_URL}/algorithm/confidence`, {
- data: { shoulderWidth: 42, bodyLength: 85, cun1: 2.2 }
- });
- const duration = Date.now() - start;
- expect([200, 401]).toContain(response.status());
- expect(duration).toBeLessThan(PERFORMANCE_THRESHOLD_MS * 2);
- });
- });
- test.describe('页面加载性能测试', () => {
- test('PERF-010: 用户列表页面加载时间', async ({ page }) => {
- await page.goto(BASE_URL);
- await page.waitForLoadState('networkidle');
- await page.getByPlaceholder('请输入用户名').fill('admin');
- await page.getByPlaceholder('请输入密码').fill('admin123');
- await page.getByRole('button', { name: '登 录' }).click();
- await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
- const start = Date.now();
- await page.goto(`${BASE_URL}/#/user/app`);
- await page.waitForLoadState('networkidle');
- const duration = Date.now() - start;
- expect(duration).toBeLessThan(3000);
- });
- test('PERF-011: 设备列表页面加载时间', async ({ page }) => {
- await page.goto(BASE_URL);
- await page.waitForLoadState('networkidle');
- await page.getByPlaceholder('请输入用户名').fill('admin');
- await page.getByPlaceholder('请输入密码').fill('admin123');
- await page.getByRole('button', { name: '登 录' }).click();
- await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
- const start = Date.now();
- await page.goto(`${BASE_URL}/#/device`);
- await page.waitForLoadState('networkidle');
- const duration = Date.now() - start;
- expect(duration).toBeLessThan(3000);
- });
- test('PERF-012: 穴位列表页面加载时间', async ({ page }) => {
- await page.goto(BASE_URL);
- await page.waitForLoadState('networkidle');
- await page.getByPlaceholder('请输入用户名').fill('admin');
- await page.getByPlaceholder('请输入密码').fill('admin123');
- await page.getByRole('button', { name: '登 录' }).click();
- await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
- const start = Date.now();
- await page.goto(`${BASE_URL}/#/acupoint`);
- await page.waitForLoadState('networkidle');
- const duration = Date.now() - start;
- expect(duration).toBeLessThan(3000);
- });
- });
|