travel-flow-refactored.spec.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { test, expect } from '@playwright/test'
  2. import { HomePage } from './pages/HomePage'
  3. import { ActivitySelectPage } from './pages/ActivitySelectPage'
  4. import { ScheduleListPage } from './pages/ScheduleListPage'
  5. test.describe('完整出行流程E2E测试', () => {
  6. let homePage: HomePage
  7. let activitySelectPage: ActivitySelectPage
  8. let scheduleListPage: ScheduleListPage
  9. test.beforeEach(async ({ page }) => {
  10. homePage = new HomePage(page)
  11. activitySelectPage = new ActivitySelectPage(page)
  12. scheduleListPage = new ScheduleListPage(page)
  13. })
  14. test('用户应该能够完成完整的出行查询流程', async ({ page }) => {
  15. // 1. 访问首页
  16. await homePage.goto()
  17. // 验证首页加载成功
  18. await expect(homePage.title).toBeVisible()
  19. await expect(homePage.subtitle).toBeVisible()
  20. // 2. 选择出行方式
  21. await homePage.selectVehicleType('商务车')
  22. await expect(homePage.isVehicleTypeSelected('商务车')).resolves.toBe(true)
  23. // 3. 选择出发地区
  24. await homePage.selectDepartureArea('北京市')
  25. await expect(page.locator('text=北京市')).toBeVisible()
  26. // 4. 选择出发地点
  27. await homePage.searchDepartureLocation('北京')
  28. await homePage.selectLocation('北京首都国际机场')
  29. await expect(homePage.getSelectedLocationText()).resolves.toContain('北京首都国际机场')
  30. // 5. 选择目的地区
  31. await homePage.selectDestinationArea('上海市')
  32. await expect(page.locator('text=上海市')).toBeVisible()
  33. // 6. 选择目的地点
  34. await homePage.searchDestinationLocation('上海')
  35. await homePage.selectLocation('上海虹桥机场')
  36. await expect(homePage.getSelectedLocationText()).resolves.toContain('上海虹桥机场')
  37. // 7. 选择日期
  38. const tomorrow = new Date()
  39. tomorrow.setDate(tomorrow.getDate() + 1)
  40. const tomorrowStr = tomorrow.toISOString().split('T')[0]
  41. await homePage.setDate(tomorrowStr)
  42. // 8. 查询路线
  43. await homePage.searchRoutes()
  44. // 9. 验证跳转到活动选择页面
  45. await activitySelectPage.waitForPageLoad()
  46. await expect(activitySelectPage.title).toBeVisible()
  47. await expect(activitySelectPage.routeInfo).toBeVisible()
  48. // 10. 选择活动
  49. await activitySelectPage.selectActivity('上海音乐节')
  50. // 11. 验证跳转到班次列表页面
  51. await scheduleListPage.waitForPageLoad()
  52. await expect(scheduleListPage.title).toBeVisible()
  53. await expect(scheduleListPage.activityInfo).toBeVisible()
  54. // 12. 选择不同日期
  55. const dayAfterTomorrow = new Date()
  56. dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 2)
  57. const dayAfterTomorrowStr = dayAfterTomorrow.toISOString().split('T')[0]
  58. await scheduleListPage.selectDate(dayAfterTomorrowStr)
  59. // 13. 验证班次列表更新
  60. await expect(scheduleListPage.dateSelector).toBeVisible()
  61. // 14. 选择班次(如果有可用班次)
  62. if (await scheduleListPage.hasSchedules()) {
  63. await scheduleListPage.selectSchedule()
  64. // 这里可以继续验证预订流程
  65. }
  66. })
  67. test('省市区三级联动功能应该正常工作', async ({ page }) => {
  68. await homePage.goto()
  69. // 测试省份选择
  70. await homePage.selectDepartureArea('广东省')
  71. await expect(page.locator('text=广东省')).toBeVisible()
  72. // 验证城市列表加载
  73. await page.click('text=请选择城市')
  74. await expect(page.locator('text=广州市')).toBeVisible()
  75. await expect(page.locator('text=深圳市')).toBeVisible()
  76. // 选择城市
  77. await page.click('text=广州市')
  78. await expect(page.locator('text=广州市')).toBeVisible()
  79. // 验证区县列表加载
  80. await page.click('text=请选择区县')
  81. await expect(page.locator('text=天河区')).toBeVisible()
  82. await expect(page.locator('text=越秀区')).toBeVisible()
  83. // 选择区县
  84. await page.click('text=天河区')
  85. await expect(page.locator('text=广东省 广州市 天河区')).toBeVisible()
  86. })
  87. test('地点搜索功能应该正常工作', async ({ page }) => {
  88. await homePage.goto()
  89. // 测试地点搜索
  90. await homePage.searchDepartureLocation('北京')
  91. // 验证搜索结果
  92. await expect(page.locator('text=北京首都国际机场')).toBeVisible()
  93. await expect(page.locator('text=北京南站')).toBeVisible()
  94. // 选择地点
  95. await homePage.selectLocation('北京首都国际机场')
  96. await expect(homePage.getSelectedLocationText()).resolves.toContain('北京首都国际机场')
  97. // 验证输入框值更新
  98. await expect(homePage.departureLocationSearch).toHaveValue('北京首都国际机场')
  99. })
  100. test('路线类型动态判断逻辑应该正确工作', async ({ page }) => {
  101. await homePage.goto()
  102. // 设置出发地和目的地
  103. await homePage.selectDepartureArea('北京市')
  104. await homePage.selectDestinationArea('上海市')
  105. // 搜索地点
  106. await homePage.searchDepartureLocation('北京首都国际机场')
  107. await homePage.selectLocation('北京首都国际机场')
  108. await homePage.searchDestinationLocation('上海虹桥机场')
  109. await homePage.selectLocation('上海虹桥机场')
  110. // 查询路线
  111. await homePage.searchRoutes()
  112. // 验证活动选择页面显示正确的路线类型
  113. await activitySelectPage.waitForPageLoad()
  114. await expect(activitySelectPage.departureActivitiesTab).toBeVisible()
  115. await expect(activitySelectPage.returnActivitiesTab).toBeVisible()
  116. })
  117. test('边界场景:无数据时应该显示友好提示', async ({ page }) => {
  118. await homePage.goto()
  119. // 设置不存在的搜索条件
  120. await homePage.searchDepartureLocation('不存在的城市')
  121. // 验证显示无结果提示
  122. await expect(homePage.noResultsText).toBeVisible()
  123. // 查询无效路线
  124. await homePage.searchRoutes()
  125. // 验证活动页面显示无活动提示
  126. await activitySelectPage.waitForPageLoad()
  127. await expect(activitySelectPage.noActivitiesText).toBeVisible()
  128. })
  129. test('并发查询应该正确处理', async ({ page }) => {
  130. await homePage.goto()
  131. // 快速连续操作
  132. await homePage.selectVehicleType('大巴拼车')
  133. await homePage.selectVehicleType('商务车')
  134. await homePage.selectVehicleType('包车')
  135. // 快速输入搜索
  136. await homePage.searchDepartureLocation('北京')
  137. await homePage.searchDepartureLocation('上海')
  138. await homePage.searchDepartureLocation('广州')
  139. await page.waitForTimeout(500) // 等待防抖完成
  140. // 验证最终状态正确
  141. await expect(homePage.isVehicleTypeSelected('包车')).resolves.toBe(true)
  142. await expect(homePage.departureLocationSearch).toHaveValue('广州')
  143. })
  144. })