import { Locator, Page } from '@playwright/test' export class ScheduleListPage { readonly page: Page // 页面元素定位器 readonly title: Locator readonly activityInfo: Locator readonly dateSelector: Locator readonly scheduleList: Locator readonly buyButton: Locator readonly noSchedulesText: Locator constructor(page: Page) { this.page = page // 初始化定位器 this.title = page.locator('text=可选班次') this.activityInfo = page.locator('text=上海音乐节') this.dateSelector = page.locator('text=选择出发日期') this.scheduleList = page.locator('text=立即购票') this.buyButton = page.locator('text=立即购票').first() this.noSchedulesText = page.locator('text=暂无可用班次') } // 页面操作方法 async waitForPageLoad() { await this.page.waitForURL(/\/pages\/schedule-list\/ScheduleListPage/) } async selectDate(date: string) { await this.page.click(`text=${date}`) } async selectSchedule() { if (await this.buyButton.isVisible()) { await this.buyButton.click() } } async getScheduleCount(): Promise { return await this.scheduleList.count() } async hasSchedules(): Promise { return await this.buyButton.isVisible() } async getActivityInfo(): Promise { return await this.activityInfo.textContent() || '' } }