|
|
@@ -0,0 +1,188 @@
|
|
|
+import { test, expect } from '@playwright/test'
|
|
|
+import { HomePage } from './pages/HomePage'
|
|
|
+import { ActivitySelectPage } from './pages/ActivitySelectPage'
|
|
|
+import { ScheduleListPage } from './pages/ScheduleListPage'
|
|
|
+
|
|
|
+test.describe('完整出行流程E2E测试', () => {
|
|
|
+ let homePage: HomePage
|
|
|
+ let activitySelectPage: ActivitySelectPage
|
|
|
+ let scheduleListPage: ScheduleListPage
|
|
|
+
|
|
|
+ test.beforeEach(async ({ page }) => {
|
|
|
+ homePage = new HomePage(page)
|
|
|
+ activitySelectPage = new ActivitySelectPage(page)
|
|
|
+ scheduleListPage = new ScheduleListPage(page)
|
|
|
+ })
|
|
|
+
|
|
|
+ test('用户应该能够完成完整的出行查询流程', async ({ page }) => {
|
|
|
+ // 1. 访问首页
|
|
|
+ await homePage.goto()
|
|
|
+
|
|
|
+ // 验证首页加载成功
|
|
|
+ await expect(homePage.title).toBeVisible()
|
|
|
+ await expect(homePage.subtitle).toBeVisible()
|
|
|
+
|
|
|
+ // 2. 选择出行方式
|
|
|
+ await homePage.selectVehicleType('商务车')
|
|
|
+ await expect(homePage.isVehicleTypeSelected('商务车')).resolves.toBe(true)
|
|
|
+
|
|
|
+ // 3. 选择出发地区
|
|
|
+ await homePage.selectDepartureArea('北京市')
|
|
|
+ await expect(page.locator('text=北京市')).toBeVisible()
|
|
|
+
|
|
|
+ // 4. 选择出发地点
|
|
|
+ await homePage.searchDepartureLocation('北京')
|
|
|
+ await homePage.selectLocation('北京首都国际机场')
|
|
|
+ await expect(homePage.getSelectedLocationText()).resolves.toContain('北京首都国际机场')
|
|
|
+
|
|
|
+ // 5. 选择目的地区
|
|
|
+ await homePage.selectDestinationArea('上海市')
|
|
|
+ await expect(page.locator('text=上海市')).toBeVisible()
|
|
|
+
|
|
|
+ // 6. 选择目的地点
|
|
|
+ await homePage.searchDestinationLocation('上海')
|
|
|
+ await homePage.selectLocation('上海虹桥机场')
|
|
|
+ await expect(homePage.getSelectedLocationText()).resolves.toContain('上海虹桥机场')
|
|
|
+
|
|
|
+ // 7. 选择日期
|
|
|
+ const tomorrow = new Date()
|
|
|
+ tomorrow.setDate(tomorrow.getDate() + 1)
|
|
|
+ const tomorrowStr = tomorrow.toISOString().split('T')[0]
|
|
|
+ await homePage.setDate(tomorrowStr)
|
|
|
+
|
|
|
+ // 8. 查询路线
|
|
|
+ await homePage.searchRoutes()
|
|
|
+
|
|
|
+ // 9. 验证跳转到活动选择页面
|
|
|
+ await activitySelectPage.waitForPageLoad()
|
|
|
+ await expect(activitySelectPage.title).toBeVisible()
|
|
|
+ await expect(activitySelectPage.routeInfo).toBeVisible()
|
|
|
+
|
|
|
+ // 10. 选择活动
|
|
|
+ await activitySelectPage.selectActivity('上海音乐节')
|
|
|
+
|
|
|
+ // 11. 验证跳转到班次列表页面
|
|
|
+ await scheduleListPage.waitForPageLoad()
|
|
|
+ await expect(scheduleListPage.title).toBeVisible()
|
|
|
+ await expect(scheduleListPage.activityInfo).toBeVisible()
|
|
|
+
|
|
|
+ // 12. 选择不同日期
|
|
|
+ const dayAfterTomorrow = new Date()
|
|
|
+ dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 2)
|
|
|
+ const dayAfterTomorrowStr = dayAfterTomorrow.toISOString().split('T')[0]
|
|
|
+ await scheduleListPage.selectDate(dayAfterTomorrowStr)
|
|
|
+
|
|
|
+ // 13. 验证班次列表更新
|
|
|
+ await expect(scheduleListPage.dateSelector).toBeVisible()
|
|
|
+
|
|
|
+ // 14. 选择班次(如果有可用班次)
|
|
|
+ if (await scheduleListPage.hasSchedules()) {
|
|
|
+ await scheduleListPage.selectSchedule()
|
|
|
+ // 这里可以继续验证预订流程
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ test('省市区三级联动功能应该正常工作', async ({ page }) => {
|
|
|
+ await homePage.goto()
|
|
|
+
|
|
|
+ // 测试省份选择
|
|
|
+ await homePage.selectDepartureArea('广东省')
|
|
|
+ await expect(page.locator('text=广东省')).toBeVisible()
|
|
|
+
|
|
|
+ // 验证城市列表加载
|
|
|
+ await page.click('text=请选择城市')
|
|
|
+ await expect(page.locator('text=广州市')).toBeVisible()
|
|
|
+ await expect(page.locator('text=深圳市')).toBeVisible()
|
|
|
+
|
|
|
+ // 选择城市
|
|
|
+ await page.click('text=广州市')
|
|
|
+ await expect(page.locator('text=广州市')).toBeVisible()
|
|
|
+
|
|
|
+ // 验证区县列表加载
|
|
|
+ await page.click('text=请选择区县')
|
|
|
+ await expect(page.locator('text=天河区')).toBeVisible()
|
|
|
+ await expect(page.locator('text=越秀区')).toBeVisible()
|
|
|
+
|
|
|
+ // 选择区县
|
|
|
+ await page.click('text=天河区')
|
|
|
+ await expect(page.locator('text=广东省 广州市 天河区')).toBeVisible()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('地点搜索功能应该正常工作', async ({ page }) => {
|
|
|
+ await homePage.goto()
|
|
|
+
|
|
|
+ // 测试地点搜索
|
|
|
+ await homePage.searchDepartureLocation('北京')
|
|
|
+
|
|
|
+ // 验证搜索结果
|
|
|
+ await expect(page.locator('text=北京首都国际机场')).toBeVisible()
|
|
|
+ await expect(page.locator('text=北京南站')).toBeVisible()
|
|
|
+
|
|
|
+ // 选择地点
|
|
|
+ await homePage.selectLocation('北京首都国际机场')
|
|
|
+ await expect(homePage.getSelectedLocationText()).resolves.toContain('北京首都国际机场')
|
|
|
+
|
|
|
+ // 验证输入框值更新
|
|
|
+ await expect(homePage.departureLocationSearch).toHaveValue('北京首都国际机场')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('路线类型动态判断逻辑应该正确工作', async ({ page }) => {
|
|
|
+ await homePage.goto()
|
|
|
+
|
|
|
+ // 设置出发地和目的地
|
|
|
+ await homePage.selectDepartureArea('北京市')
|
|
|
+ await homePage.selectDestinationArea('上海市')
|
|
|
+
|
|
|
+ // 搜索地点
|
|
|
+ await homePage.searchDepartureLocation('北京首都国际机场')
|
|
|
+ await homePage.selectLocation('北京首都国际机场')
|
|
|
+
|
|
|
+ await homePage.searchDestinationLocation('上海虹桥机场')
|
|
|
+ await homePage.selectLocation('上海虹桥机场')
|
|
|
+
|
|
|
+ // 查询路线
|
|
|
+ await homePage.searchRoutes()
|
|
|
+
|
|
|
+ // 验证活动选择页面显示正确的路线类型
|
|
|
+ await activitySelectPage.waitForPageLoad()
|
|
|
+ await expect(activitySelectPage.departureActivitiesTab).toBeVisible()
|
|
|
+ await expect(activitySelectPage.returnActivitiesTab).toBeVisible()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('边界场景:无数据时应该显示友好提示', async ({ page }) => {
|
|
|
+ await homePage.goto()
|
|
|
+
|
|
|
+ // 设置不存在的搜索条件
|
|
|
+ await homePage.searchDepartureLocation('不存在的城市')
|
|
|
+
|
|
|
+ // 验证显示无结果提示
|
|
|
+ await expect(homePage.noResultsText).toBeVisible()
|
|
|
+
|
|
|
+ // 查询无效路线
|
|
|
+ await homePage.searchRoutes()
|
|
|
+
|
|
|
+ // 验证活动页面显示无活动提示
|
|
|
+ await activitySelectPage.waitForPageLoad()
|
|
|
+ await expect(activitySelectPage.noActivitiesText).toBeVisible()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('并发查询应该正确处理', async ({ page }) => {
|
|
|
+ await homePage.goto()
|
|
|
+
|
|
|
+ // 快速连续操作
|
|
|
+ await homePage.selectVehicleType('大巴拼车')
|
|
|
+ await homePage.selectVehicleType('商务车')
|
|
|
+ await homePage.selectVehicleType('包车')
|
|
|
+
|
|
|
+ // 快速输入搜索
|
|
|
+ await homePage.searchDepartureLocation('北京')
|
|
|
+ await homePage.searchDepartureLocation('上海')
|
|
|
+ await homePage.searchDepartureLocation('广州')
|
|
|
+
|
|
|
+ await page.waitForTimeout(500) // 等待防抖完成
|
|
|
+
|
|
|
+ // 验证最终状态正确
|
|
|
+ await expect(homePage.isVehicleTypeSelected('包车')).resolves.toBe(true)
|
|
|
+ await expect(homePage.departureLocationSearch).toHaveValue('广州')
|
|
|
+ })
|
|
|
+})
|