ScheduleListPage.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Locator, Page } from '@playwright/test'
  2. export class ScheduleListPage {
  3. readonly page: Page
  4. // 页面元素定位器
  5. readonly title: Locator
  6. readonly activityInfo: Locator
  7. readonly dateSelector: Locator
  8. readonly scheduleList: Locator
  9. readonly buyButton: Locator
  10. readonly noSchedulesText: Locator
  11. constructor(page: Page) {
  12. this.page = page
  13. // 初始化定位器
  14. this.title = page.locator('text=可选班次')
  15. this.activityInfo = page.locator('text=上海音乐节')
  16. this.dateSelector = page.locator('text=选择出发日期')
  17. this.scheduleList = page.locator('text=立即购票')
  18. this.buyButton = page.locator('text=立即购票').first()
  19. this.noSchedulesText = page.locator('text=暂无可用班次')
  20. }
  21. // 页面操作方法
  22. async waitForPageLoad() {
  23. await this.page.waitForURL(/\/pages\/schedule-list\/ScheduleListPage/)
  24. }
  25. async selectDate(date: string) {
  26. await this.page.click(`text=${date}`)
  27. }
  28. async selectSchedule() {
  29. if (await this.buyButton.isVisible()) {
  30. await this.buyButton.click()
  31. }
  32. }
  33. async getScheduleCount(): Promise<number> {
  34. return await this.scheduleList.count()
  35. }
  36. async hasSchedules(): Promise<boolean> {
  37. return await this.buyButton.isVisible()
  38. }
  39. async getActivityInfo(): Promise<string> {
  40. return await this.activityInfo.textContent() || ''
  41. }
  42. }