import { test, expect } from '@playwright/test'; test.describe('访客浏览旅程 @journey @visitor', () => { test('访客浏览首页并了解公司信息', async ({ page }) => { await test.step('步骤1: 访问首页', async () => { await page.goto('/'); await expect(page).toHaveTitle(/四川睿新致远科技有限公司/); }); await test.step('步骤2: 查看Hero区域', async () => { await expect(page.locator('h1')).toBeVisible(); await expect(page.locator('text=专业')).toBeVisible(); }); await test.step('步骤3: 滚动查看服务介绍', async () => { await page.locator('#services').scrollIntoViewIfNeeded(); await expect(page.locator('#services')).toBeVisible(); }); await test.step('步骤4: 查看产品展示', async () => { await page.locator('#products').scrollIntoViewIfNeeded(); await expect(page.locator('#products')).toBeVisible(); }); await test.step('步骤5: 查看最新资讯', async () => { await page.locator('#news').scrollIntoViewIfNeeded(); await expect(page.locator('#news')).toBeVisible(); }); }); test('访客浏览新闻列表并查看详情', async ({ page }) => { await test.step('步骤1: 访问新闻列表页', async () => { await page.goto('/news'); await expect(page).toHaveURL(/\/news/); }); await test.step('步骤2: 查看新闻列表', async () => { const newsCards = page.locator('article, [data-testid="news-card"]'); const count = await newsCards.count(); expect(count).toBeGreaterThan(0); }); await test.step('步骤3: 点击第一条新闻', async () => { const firstNews = page.locator('article a, [data-testid="news-card"] a').first(); if (await firstNews.count() > 0) { await firstNews.click(); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); } }); }); test('访客浏览产品并了解详情', async ({ page }) => { await test.step('步骤1: 访问产品列表页', async () => { await page.goto('/products'); await expect(page).toHaveURL(/\/products/); }); await test.step('步骤2: 查看产品列表', async () => { const productCards = page.locator('article, [data-testid="product-card"]'); const count = await productCards.count(); expect(count).toBeGreaterThan(0); }); await test.step('步骤3: 点击第一个产品', async () => { const firstProduct = page.locator('article a, [data-testid="product-card"] a').first(); if (await firstProduct.count() > 0) { await firstProduct.click(); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); } }); }); test('访客查看联系信息并提交表单', async ({ page }) => { await test.step('步骤1: 访问联系页面', async () => { await page.goto('/contact'); await expect(page).toHaveURL(/\/contact/); }); await test.step('步骤2: 查看联系信息', async () => { await expect(page.locator('text=电话')).toBeVisible(); await expect(page.locator('text=邮箱')).toBeVisible(); }); await test.step('步骤3: 填写联系表单', async () => { const form = page.locator('form'); if (await form.count() > 0) { await page.fill('input[name="name"]', '测试用户'); await page.fill('input[name="email"]', 'test@example.com'); await page.fill('textarea[name="message"]', '这是一条测试留言'); } }); }); });