|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Helper function to verify the presence of multiple sections on a page. |
| 5 | + */ |
| 6 | +export async function expectSections({ page, pageName, sections } : { |
| 7 | + page: import('@playwright/test').Page, |
| 8 | + pageName: string, |
| 9 | + sections: string[], |
| 10 | +}) { |
| 11 | + for (const section of sections) { |
| 12 | + const locator = `data-test=${pageName}-${section}`; |
| 13 | + await expect(page.locator(locator)).toBeVisible(); |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +export async function expectH1AndTitle({ page, h1, title } : { |
| 18 | + page: import('@playwright/test').Page, |
| 19 | + h1: string | RegExp, |
| 20 | + title: string | RegExp, |
| 21 | +}) { |
| 22 | + await expect(page.locator('h1')).toHaveText(h1); |
| 23 | + await expect(page).toHaveTitle(title); |
| 24 | +} |
| 25 | + |
| 26 | +export async function expectLinks({ page, pageName, links } : { |
| 27 | + page: import('@playwright/test').Page, |
| 28 | + pageName: string, |
| 29 | + links: { linkLocator: string, destLocator: string, destText?: string | RegExp }[], |
| 30 | +}) { |
| 31 | + for (const { linkLocator, destLocator, destText } of links) { |
| 32 | + const link = page.locator(`data-test=${pageName}-${linkLocator}`); |
| 33 | + |
| 34 | + await link.click(); |
| 35 | + await expect(page.locator(destLocator)).toBeVisible(); |
| 36 | + |
| 37 | + if (destText !== undefined) { |
| 38 | + await expect(page.locator(destLocator)).toHaveText(destText); |
| 39 | + } |
| 40 | + |
| 41 | + // go back to the previous page for the next link test |
| 42 | + await page.goBack(); |
| 43 | + } |
| 44 | +} |
0 commit comments