feat(e2e): 添加完整的E2E测试框架和测试用例

添加Playwright测试框架配置和基础页面对象
实现冒烟测试用例覆盖首页和联系页面核心功能
更新导航组件以支持滚动高亮功能
添加BackButton组件统一返回按钮行为
配置Woodpecker CI集成和测试报告生成
This commit is contained in:
张翔
2026-02-27 10:30:33 +08:00
parent 4a616fe96e
commit 5d5b7feb0a
50 changed files with 6765 additions and 46 deletions
+137
View File
@@ -0,0 +1,137 @@
import { test, expect } from '../../fixtures/base.fixture';
test.describe('首页冒烟测试 @smoke', () => {
test.beforeEach(async ({ homePage }) => {
await homePage.goto();
await homePage.waitForPageLoad();
});
test('应该成功加载首页', async ({ homePage }) => {
await expect(homePage.page).toHaveURL(/\/$/);
await expect(homePage.header).toBeVisible();
await expect(homePage.heroSection).toBeVisible();
await expect(homePage.footer).toBeVisible();
});
test('应该显示正确的页面标题', async ({ homePage }) => {
const title = await homePage.getTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示Logo', async ({ homePage }) => {
await expect(homePage.logo).toBeVisible();
const altText = await homePage.getLogoAltText();
expect(altText).toBeTruthy();
});
test('应该显示主导航菜单', async ({ homePage }) => {
await expect(homePage.navigation).toBeVisible();
const navItems = await homePage.getNavigationItemCount();
expect(navItems).toBeGreaterThan(0);
});
test('应该显示所有主要区块', async ({ homePage }) => {
await expect(homePage.heroSection).toBeVisible();
await homePage.scrollToSection('services');
await expect(homePage.servicesSection).toBeVisible();
await homePage.scrollToSection('products');
await expect(homePage.productsSection).toBeVisible();
await homePage.scrollToSection('cases');
await expect(homePage.casesSection).toBeVisible();
await homePage.scrollToSection('about');
await expect(homePage.aboutSection).toBeVisible();
await homePage.scrollToSection('news');
await expect(homePage.newsSection).toBeVisible();
await homePage.scrollToSection('contact');
await expect(homePage.contactSection).toBeVisible();
});
test('应该显示页脚', async ({ homePage }) => {
await homePage.scrollToBottom();
await expect(homePage.footer).toBeVisible();
const footerText = await homePage.getFooterText();
expect(footerText.length).toBeGreaterThan(0);
});
test('应该能够滚动到页面底部', async ({ homePage }) => {
await homePage.scrollToBottom();
const scrollPosition = await homePage.page.evaluate(() => window.scrollY);
expect(scrollPosition).toBeGreaterThan(0);
});
test('应该能够滚动到页面顶部', async ({ homePage }) => {
await homePage.scrollToBottom();
await homePage.scrollToTop();
const scrollPosition = await homePage.page.evaluate(() => window.scrollY);
expect(scrollPosition).toBe(0);
});
test('应该显示Hero区块标题', async ({ homePage }) => {
const title = await homePage.getHeroSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示Services区块标题', async ({ homePage }) => {
await homePage.waitForServicesSection();
const title = await homePage.getServicesSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示Products区块标题', async ({ homePage }) => {
await homePage.waitForProductsSection();
const title = await homePage.getProductsSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示Cases区块标题', async ({ homePage }) => {
await homePage.waitForCasesSection();
const title = await homePage.getCasesSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示About区块标题', async ({ homePage }) => {
await homePage.waitForAboutSection();
const title = await homePage.getAboutSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示News区块标题', async ({ homePage }) => {
await homePage.waitForNewsSection();
const title = await homePage.getNewsSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该显示Contact区块标题', async ({ homePage }) => {
await homePage.waitForContactSection();
const title = await homePage.getContactSectionTitle();
expect(title).toBeTruthy();
expect(title.length).toBeGreaterThan(0);
});
test('应该有正确的导航标签', async ({ homePage }) => {
const labels = await homePage.getAllNavigationLabels();
expect(labels.length).toBeGreaterThan(0);
labels.forEach(label => {
expect(label).toBeTruthy();
expect(label.length).toBeGreaterThan(0);
});
});
test('应该没有控制台错误', async ({ homePage, page }) => {
const errors: string[] = [];
page.on('console', msg => {
if (msg.type() === 'error') {
errors.push(msg.text());
}
});
await homePage.waitForPageLoad();
expect(errors.length).toBe(0);
});
});