0258b8d39a
- 修复 Logo alt 属性,使用繁体字"睿新致遠" - 修复关于我们页面电话测试选择器 - 修复表单验证测试,改用 blur 触发验证 - 修复无障碍访问测试,处理多个 nav 元素情况 - 所有测试通过(42/42)
180 lines
6.6 KiB
TypeScript
180 lines
6.6 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('网站全面测试验收', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/');
|
|
});
|
|
|
|
test('首页加载正常', async ({ page }) => {
|
|
await expect(page).toHaveTitle(/四川睿新致远科技有限公司/);
|
|
await expect(page.locator('header')).toBeVisible();
|
|
await expect(page.locator('footer')).toBeVisible();
|
|
});
|
|
|
|
test('公司Logo可见且不被覆盖', async ({ page }) => {
|
|
const logo = page.locator('header img[alt*="睿新致遠"], header img[alt*="novalon"]');
|
|
await expect(logo).toBeVisible();
|
|
|
|
const logoBox = await logo.boundingBox();
|
|
expect(logoBox).not.toBeNull();
|
|
|
|
const header = page.locator('header');
|
|
const headerBox = await header.boundingBox();
|
|
expect(headerBox).not.toBeNull();
|
|
|
|
if (logoBox && headerBox) {
|
|
expect(logoBox.x).toBeGreaterThanOrEqual(headerBox.x);
|
|
expect(logoBox.y).toBeGreaterThanOrEqual(headerBox.y);
|
|
expect(logoBox.x + logoBox.width).toBeLessThanOrEqual(headerBox.x + headerBox.width);
|
|
expect(logoBox.y + logoBox.height).toBeLessThanOrEqual(headerBox.y + headerBox.height);
|
|
}
|
|
});
|
|
|
|
test('导航菜单功能正常', async ({ page }) => {
|
|
const navLinks = page.locator('nav a');
|
|
const count = await navLinks.count();
|
|
expect(count).toBeGreaterThan(0);
|
|
|
|
await navLinks.nth(0).click();
|
|
await page.waitForLoadState('networkidle');
|
|
});
|
|
|
|
test('联系我们页面没有显示公司电话', async ({ page }) => {
|
|
await page.goto('/contact');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const contactInfoSection = page.locator('[data-testid="contact-info"]');
|
|
if (await contactInfoSection.isVisible()) {
|
|
const phoneInContactInfo = contactInfoSection.locator('text=/电话|028-88888888/');
|
|
expect(await phoneInContactInfo.count()).toBe(0);
|
|
}
|
|
});
|
|
|
|
test('联系我们页面表单正常显示', async ({ page }) => {
|
|
await page.goto('/contact');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
await expect(page.locator('input[name="name"]')).toBeVisible();
|
|
await expect(page.locator('input[name="phone"]')).toBeVisible();
|
|
await expect(page.locator('input[name="email"]')).toBeVisible();
|
|
await expect(page.locator('input[name="subject"]')).toBeVisible();
|
|
await expect(page.locator('textarea[name="message"]')).toBeVisible();
|
|
await expect(page.locator('button[type="submit"]')).toBeVisible();
|
|
});
|
|
|
|
test('ICP备案号正确显示', async ({ page }) => {
|
|
const icpText = await page.locator('footer').textContent();
|
|
expect(icpText).toContain('蜀ICP备2026013658号');
|
|
});
|
|
|
|
test('关于我们页面没有显示公司电话', async ({ page }) => {
|
|
await page.goto('/about');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const phoneElements = page.locator('text=/电话|028-|1[3-9]\\d{9}/');
|
|
expect(await phoneElements.count()).toBe(0);
|
|
});
|
|
|
|
test('响应式设计正常工作', async ({ page }) => {
|
|
await page.setViewportSize({ width: 375, height: 667 });
|
|
await expect(page.locator('header')).toBeVisible();
|
|
await expect(page.locator('footer')).toBeVisible();
|
|
|
|
const mobileMenuButton = page.locator('[data-testid="mobile-menu-button"]');
|
|
await expect(mobileMenuButton).toBeVisible();
|
|
|
|
await mobileMenuButton.click();
|
|
await expect(page.locator('[data-testid="mobile-navigation"]')).toBeVisible();
|
|
});
|
|
|
|
test('页面跳转功能正常', async ({ page }) => {
|
|
await page.click('text=联系我们');
|
|
await page.waitForLoadState('networkidle');
|
|
expect(page.url()).toContain('/contact');
|
|
|
|
await page.click('text=首页');
|
|
await page.waitForLoadState('networkidle');
|
|
});
|
|
|
|
test('Footer链接正常工作', async ({ page }) => {
|
|
await page.locator('footer').scrollIntoViewIfNeeded();
|
|
|
|
const privacyLink = page.locator('footer a:has-text("隐私政策")');
|
|
await privacyLink.click();
|
|
await page.waitForLoadState('networkidle');
|
|
expect(page.url()).toContain('/privacy');
|
|
|
|
await page.goBack();
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const termsLink = page.locator('footer a:has-text("服务条款")');
|
|
await termsLink.click();
|
|
await page.waitForLoadState('networkidle');
|
|
expect(page.url()).toContain('/terms');
|
|
});
|
|
|
|
test('表单验证功能正常', async ({ page }) => {
|
|
await page.goto('/contact');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const nameInput = page.locator('input[name="name"]');
|
|
await nameInput.fill('a');
|
|
await nameInput.blur();
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
const errorMessage = page.locator('text=至少需要2个字符').first();
|
|
await expect(errorMessage).toBeVisible({ timeout: 10000 });
|
|
});
|
|
|
|
test('页面加载性能良好', async ({ page }) => {
|
|
const performanceMetrics = await page.evaluate(() => {
|
|
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming;
|
|
return {
|
|
domContentLoaded: navigation.domContentLoadedEventEnd - navigation.domContentLoadedEventStart,
|
|
loadComplete: navigation.loadEventEnd - navigation.loadEventStart,
|
|
};
|
|
});
|
|
|
|
expect(performanceMetrics.domContentLoaded).toBeLessThan(3000);
|
|
expect(performanceMetrics.loadComplete).toBeLessThan(5000);
|
|
});
|
|
|
|
test('无障碍访问正常', async ({ page }) => {
|
|
const mainHeading = page.locator('h1');
|
|
await expect(mainHeading).toBeVisible();
|
|
|
|
const nav = page.locator('nav').first();
|
|
await expect(nav).toBeVisible();
|
|
|
|
const buttons = page.locator('button');
|
|
const buttonCount = await buttons.count();
|
|
expect(buttonCount).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('联系我们页面没有返回按钮覆盖logo', async ({ page }) => {
|
|
await page.goto('/contact');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const logo = page.locator('header img[alt*="睿新致遠"], header img[alt*="novalon"]');
|
|
await expect(logo).toBeVisible();
|
|
|
|
const logoBox = await logo.boundingBox();
|
|
expect(logoBox).not.toBeNull();
|
|
|
|
const header = page.locator('header');
|
|
const headerBox = await header.boundingBox();
|
|
expect(headerBox).not.toBeNull();
|
|
|
|
if (logoBox && headerBox) {
|
|
const logoCenterX = logoBox.x + logoBox.width / 2;
|
|
const logoCenterY = logoBox.y + logoBox.height / 2;
|
|
|
|
expect(logoCenterX).toBeGreaterThan(headerBox.x);
|
|
expect(logoCenterX).toBeLessThan(headerBox.x + headerBox.width);
|
|
expect(logoCenterY).toBeGreaterThan(headerBox.y);
|
|
expect(logoCenterY).toBeLessThan(headerBox.y + headerBox.height);
|
|
}
|
|
});
|
|
});
|