Skip to content

Commit 4a02bc9

Browse files
committed
refactor: implement MdPage class for whitepaper tests
1 parent 8fe00dc commit 4a02bc9

File tree

2 files changed

+68
-7
lines changed

2 files changed

+68
-7
lines changed

tests/e2e/pages/MdPage.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

tests/e2e/whitepaper.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { expect, request, test } from "@playwright/test"
22

3+
import { MdPage } from "./pages/MdPage"
4+
35
const PAGE_URL = "/whitepaper"
46
const PDF_LINK_TEXT = /whitepaper.*pdf/i
57
const PDF_PATH =
68
"/content/whitepaper/whitepaper-pdf/Ethereum_Whitepaper_-_Buterin_2014.pdf"
79

810
test.describe("Whitepaper Page", () => {
911
test("whitepaper PDF link has correct href", async ({ page }) => {
10-
await page.goto(PAGE_URL)
11-
12-
const pdfLink = page.getByRole("link", { name: PDF_LINK_TEXT })
13-
await expect(pdfLink).toBeVisible()
14-
15-
const href = await pdfLink.getAttribute("href")
16-
expect(href).toContain(PDF_PATH)
12+
const whitepaperPage = new MdPage(page, PAGE_URL)
13+
await whitepaperPage.goto()
14+
await whitepaperPage.waitForPageReady()
15+
await whitepaperPage.verifyLinkVisible(PDF_LINK_TEXT)
16+
await whitepaperPage.verifyLinkHref(PDF_LINK_TEXT, PDF_PATH)
1717
})
1818

1919
test("whitepaper PDF is accessible and served as PDF", async ({

0 commit comments

Comments
 (0)