| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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<number> {
- return await this.scheduleList.count()
- }
- async hasSchedules(): Promise<boolean> {
- return await this.buyButton.isVisible()
- }
- async getActivityInfo(): Promise<string> {
- return await this.activityInfo.textContent() || ''
- }
- }
|