162 lines
5.9 KiB
TypeScript
162 lines
5.9 KiB
TypeScript
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 }) => {
|
|
const isMobile = await homePage.mobileMenuButton.isVisible();
|
|
if (isMobile) {
|
|
await expect(homePage.mobileMenuButton).toBeVisible();
|
|
} else {
|
|
await expect(homePage.desktopNavigation).toBeVisible();
|
|
}
|
|
const navItems = await homePage.getNavigationItemCount();
|
|
expect(navItems).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('移动端应该显示导航菜单按钮', async ({ homePage, page }) => {
|
|
await page.setViewportSize({ width: 375, height: 667 });
|
|
await expect(homePage.mobileMenuButton).toBeVisible();
|
|
});
|
|
|
|
test('应该显示立即咨询按钮', async ({ homePage }) => {
|
|
const isMobile = await homePage.mobileMenuButton.isVisible();
|
|
if (isMobile) {
|
|
await homePage.mobileMenuButton.click();
|
|
await expect(homePage.mobileNavigation).toBeVisible();
|
|
const consultButton = homePage.mobileNavigation.locator('a[href="/contact"]').first();
|
|
await expect(consultButton).toBeVisible();
|
|
} else {
|
|
await expect(homePage.consultButton).toBeVisible();
|
|
}
|
|
});
|
|
|
|
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.waitForFooter();
|
|
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();
|
|
const bottomScrollPosition = await homePage.page.evaluate(() => window.scrollY);
|
|
await homePage.scrollToTop();
|
|
const topScrollPosition = await homePage.page.evaluate(() => window.scrollY);
|
|
expect(topScrollPosition).toBeLessThan(bottomScrollPosition);
|
|
});
|
|
|
|
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 }) => {
|
|
test.skip(true, 'Contact区块不在首页上,此测试已跳过');
|
|
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);
|
|
});
|
|
});
|