import { test, expect } from '@playwright/test'; import { FrontendHomePage, FrontendContactPage, FrontendProductPage } from '../../pages/frontend'; import { TestDataFactory } from '../../fixtures/test-data-factory'; test.describe('访客转化旅程 @journey @visitor @conversion', () => { let homePage: FrontendHomePage; let contactPage: FrontendContactPage; let productPage: FrontendProductPage; test.beforeEach(async ({ page }) => { homePage = new FrontendHomePage(page); contactPage = new FrontendContactPage(page); productPage = new FrontendProductPage(page); }); test('访客从首页浏览到提交咨询的完整旅程', async ({ page }) => { const contactData = TestDataFactory.createContactForm(); await test.step('步骤1: 访客着陆首页', async () => { await homePage.goto(); await homePage.expectHeroVisible(); await homePage.expectServicesVisible(); }); await test.step('步骤2: 浏览服务介绍,建立初步认知', async () => { await homePage.scrollToSection('services'); await homePage.expectServiceCardsVisible(); }); await test.step('步骤3: 查看成功案例,建立信任', async () => { await homePage.scrollToSection('cases'); await homePage.clickFirstCase(); await page.waitForURL(/\/cases\/\d+/); await expect(page.locator('h1')).toBeVisible(); }); await test.step('步骤4: 返回首页,查看产品详情', async () => { await homePage.goto(); await homePage.scrollToSection('products'); await homePage.clickFirstProduct(); await page.waitForURL(/\/products\/\d+/); await expect(page.locator('h1')).toBeVisible(); }); await test.step('步骤5: 决定咨询,访问联系页面', async () => { await contactPage.goto(); await contactPage.expectContactInfoVisible(); }); await test.step('步骤6: 填写并提交联系表单', async () => { await contactPage.fillForm(contactData); await contactPage.submitForm(); await contactPage.expectSubmitSuccess(); }); await test.step('步骤7: 验证收到确认提示', async () => { await contactPage.expectConfirmationVisible(); }); }); test('访客从搜索引擎着陆到产品详情页', async ({ page }) => { await test.step('步骤1: 模拟搜索引擎着陆(直接访问产品详情页)', async () => { await page.goto('/products/1'); await expect(page.locator('h1')).toBeVisible(); }); await test.step('步骤2: 查看产品详情', async () => { await productPage.expectProductDetailsVisible(); }); await test.step('步骤3: 浏览相关案例', async () => { const relatedCasesLink = page.locator('a:has-text("相关案例")'); if (await relatedCasesLink.count() > 0) { await relatedCasesLink.click(); await page.waitForURL(/\/cases/); } }); await test.step('步骤4: 返回首页或提交咨询', async () => { const contactButton = page.locator('a:has-text("联系我们")'); if (await contactButton.count() > 0) { await contactButton.click(); await page.waitForURL(/\/contact/); } }); }); });