|
1 | 1 | import AxeBuilder from "@axe-core/playwright"; |
2 | | -import { Page, TestInfo, expect } from "@playwright/test"; |
| 2 | +import { Locator, Page, TestInfo, expect } from "@playwright/test"; |
3 | 3 | import { snapshotPathTemplate } from "@project/playwright.config"; |
4 | 4 |
|
5 | 5 | declare global { |
@@ -75,23 +75,29 @@ export const accessibilityCheck = async (page: Page) => { |
75 | 75 | export const pathForCustomScreenshots = (testFileName: string, screenshotFileName: string, projectName: string) => { |
76 | 76 | const baseFile: string = screenshotFileName.substring(0, screenshotFileName.lastIndexOf(".")); |
77 | 77 |
|
78 | | - const path = snapshotPathTemplate |
| 78 | + return snapshotPathTemplate |
79 | 79 | .replace("{testDir}", "./e2e") |
80 | 80 | .replace("__snapshots__", "snapshot_review") |
81 | 81 | .replace("{testFileName}", testFileName) |
82 | 82 | .replace("{arg}", baseFile) |
83 | 83 | .replace("{projectName}", projectName) |
84 | 84 | .replace("{platform}", process.platform) |
85 | 85 | .replace("{ext}", ".png"); |
86 | | - |
87 | | - return path; |
88 | 86 | }; |
89 | 87 |
|
90 | | -export const openExpanders = async (page: Page) => { |
91 | | - const expanderTitles = ["What the vaccine is for", "Who should have the vaccine", "Side effects of the vaccine"]; |
| 88 | +export const openExpandersIfPresent = async (page: Page) => { |
| 89 | + const expanderTitles = [ |
| 90 | + "What the vaccine is for", |
| 91 | + "Who should have the vaccine", |
| 92 | + "How to get the vaccine", |
| 93 | + "Side effects of the vaccine", |
| 94 | + ]; |
92 | 95 |
|
93 | 96 | for (const title of expanderTitles) { |
94 | | - await page.getByText(title).click(); |
| 97 | + const expander: Locator = page.getByText(title); |
| 98 | + if ((await expander.count()) > 0) { |
| 99 | + await expander.click(); |
| 100 | + } |
95 | 101 | } |
96 | 102 |
|
97 | 103 | await page.mouse.click(0, 0); |
|
0 commit comments