feat: 创建冒烟测试(快速层)

新增文件:
- e2e/smoke/health-check.spec.ts - 健康检查测试
- e2e/smoke/critical-paths.spec.ts - 关键路径测试

测试内容:
- 应用启动验证
- 健康检查API验证
- 静态资源访问验证
- 首页加载验证
- 管理员登录验证
- 新闻/产品/联系页面访问验证

特性:
- 使用 @smoke @critical 标签,支持按标签运行
- 快速验证核心功能,适合CI/CD流水线
- 测试执行时间短,无复杂依赖
This commit is contained in:
张翔
2026-04-09 13:23:06 +08:00
parent 79a66612bd
commit 07d2315935
2 changed files with 60 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { test, expect } from '@playwright/test';
import { testFixtures } from '../fixtures/test-data';
test.describe('关键路径测试 @smoke @critical', () => {
test('首页加载正常', async ({ page }) => {
await page.goto('/');
await expect(page.locator('header')).toBeVisible();
await expect(page.locator('footer')).toBeVisible();
await expect(page.locator('nav')).toBeVisible();
});
test('管理员能够登录', async ({ page }) => {
await page.goto('/admin/login');
await page.fill('#email', testFixtures.adminUser.email);
await page.fill('#password', testFixtures.adminUser.password);
await page.click('button[type="submit"]');
await expect(page).toHaveURL(/\/admin(?!\/login)/);
});
test('新闻页面可访问', async ({ page }) => {
await page.goto('/news');
await expect(page).toHaveURL(/\/news/);
await expect(page.locator('header')).toBeVisible();
});
test('产品页面可访问', async ({ page }) => {
await page.goto('/products');
await expect(page).toHaveURL(/\/products/);
await expect(page.locator('header')).toBeVisible();
});
test('联系页面可访问', async ({ page }) => {
await page.goto('/contact');
await expect(page).toHaveURL(/\/contact/);
await expect(page.locator('form')).toBeVisible();
});
});
+21
View File
@@ -0,0 +1,21 @@
import { test, expect } from '@playwright/test';
test.describe('健康检查 @smoke @critical', () => {
test('应用能够正常启动', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/四川睿新致远科技有限公司/);
});
test('健康检查API正常', async ({ request }) => {
const response = await request.get('/api/health');
expect(response.status()).toBe(200);
const body = await response.json();
expect(body.status).toBe('ok');
});
test('静态资源可访问', async ({ request }) => {
const response = await request.get('/favicon.svg');
expect(response.status()).toBe(200);
});
});