|
| 1 | +import { expect, Locator, Page } from "@playwright/test" |
| 2 | + |
| 3 | +import { BasePage } from "./BasePage" |
| 4 | + |
| 5 | +/** |
| 6 | + * Generic Page Object Model for markdown pages |
| 7 | + */ |
| 8 | +export class MdPage extends BasePage { |
| 9 | + protected url: string |
| 10 | + |
| 11 | + constructor(page: Page, url: string) { |
| 12 | + super(page) |
| 13 | + this.url = url |
| 14 | + } |
| 15 | + |
| 16 | + /** |
| 17 | + * Navigate to the markdown page |
| 18 | + */ |
| 19 | + async goto() { |
| 20 | + await this.navigateTo(this.url) |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Verify the markdown page has loaded successfully |
| 25 | + */ |
| 26 | + async verifyPageLoaded() { |
| 27 | + await this.waitForPageReady() |
| 28 | + await expect(this.page.locator("main")).toBeVisible() |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Find a link by text pattern and return its locator |
| 33 | + */ |
| 34 | + getLinkByText(textPattern: string | RegExp): Locator { |
| 35 | + return this.page.getByRole("link", { name: textPattern }) |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Verify a link is visible |
| 40 | + */ |
| 41 | + async verifyLinkVisible(textPattern: string | RegExp) { |
| 42 | + const link = this.getLinkByText(textPattern) |
| 43 | + await expect(link).toBeVisible() |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Get the href attribute of a link |
| 48 | + */ |
| 49 | + async getLinkHref(textPattern: string | RegExp): Promise<string | null> { |
| 50 | + const link = this.getLinkByText(textPattern) |
| 51 | + return await link.getAttribute("href") |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Verify a link has the correct href |
| 56 | + */ |
| 57 | + async verifyLinkHref(textPattern: string | RegExp, expectedPath: string) { |
| 58 | + const href = await this.getLinkHref(textPattern) |
| 59 | + expect(href).toContain(expectedPath) |
| 60 | + } |
| 61 | +} |
0 commit comments