|
1 |
| -import { expect, Page } from "@playwright/test" |
| 1 | +import { expect, Locator, Page } from "@playwright/test" |
2 | 2 |
|
3 | 3 | import { breakpointAsNumber } from "@/lib/utils/screen"
|
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * Base page class with common functionality for all pages
|
7 | 7 | */
|
8 | 8 | export class BasePage {
|
9 |
| - constructor(protected page: Page) {} |
| 9 | + // Locators |
| 10 | + readonly searchButtonMobile: Locator |
| 11 | + readonly searchInputButton: Locator |
| 12 | + readonly searchInput: Locator |
| 13 | + readonly searchModal: Locator |
| 14 | + readonly searchResults: Locator |
| 15 | + readonly primaryNav: Locator |
| 16 | + readonly mobileMenuButton: Locator |
| 17 | + readonly mobileSidebar: Locator |
| 18 | + |
| 19 | + constructor(protected page: Page) { |
| 20 | + this.searchButtonMobile = page.getByTestId("search-button-mobile") |
| 21 | + this.searchInputButton = page.getByTestId("search-input-button") |
| 22 | + this.searchInput = page.getByPlaceholder("Search") |
| 23 | + this.searchModal = page.getByTestId("search-modal") |
| 24 | + this.searchResults = page.getByRole("listbox") |
| 25 | + this.primaryNav = page.getByRole("navigation", { name: "Primary" }) |
| 26 | + this.mobileMenuButton = this.primaryNav.getByRole("button", { |
| 27 | + name: /toggle menu button/i, |
| 28 | + }) |
| 29 | + this.mobileSidebar = page.getByRole("dialog", { name: /ethereum.org/i }) |
| 30 | + } |
10 | 31 |
|
11 | 32 | /**
|
12 | 33 | * Check if the current viewport is mobile
|
@@ -89,27 +110,15 @@ export class BasePage {
|
89 | 110 | * Open language picker in desktop view
|
90 | 111 | */
|
91 | 112 | async openLanguagePickerDesktop(): Promise<void> {
|
92 |
| - const nav = this.page.getByRole("navigation", { name: /primary/i }) |
93 |
| - const langButton = nav.getByRole("button", { name: /languages/i }) |
94 |
| - await expect(langButton).toBeVisible() |
95 |
| - await langButton.click() |
| 113 | + await this.primaryNav.getByRole("button", { name: /languages/i }).click() |
96 | 114 | }
|
97 | 115 |
|
98 | 116 | /**
|
99 | 117 | * Open language picker in mobile view
|
100 | 118 | */
|
101 | 119 | async openLanguagePickerMobile(): Promise<void> {
|
102 |
| - const nav = this.page.getByRole("navigation", { name: /primary/i }) |
103 |
| - const menuButton = nav.getByRole("button", { |
104 |
| - name: /toggle menu button/i, |
105 |
| - }) |
106 |
| - await expect(menuButton).toBeVisible() |
107 |
| - await menuButton.click() |
108 |
| - const sidebar = this.page.getByRole("dialog", { name: /ethereum.org/i }) |
109 |
| - await expect(sidebar).toBeVisible() |
110 |
| - const langButton = sidebar.getByRole("button", { name: /languages/i }) |
111 |
| - await expect(langButton).toBeVisible() |
112 |
| - await langButton.click() |
| 120 | + await this.mobileMenuButton.click() |
| 121 | + await this.mobileSidebar.getByRole("button", { name: /languages/i }).click() |
113 | 122 | }
|
114 | 123 |
|
115 | 124 | /**
|
|
0 commit comments