Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 67x 67x 1x 1x 1x 1x 1x 1x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // @ts-check
const { expect } = require('@playwright/test');
/**
* BasePage provides shared functionality, resilient action helpers,
* and assertions across all page objects.
*/
class BasePage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
this.page = page;
}
/**
* Navigates to a specific relative or absolute path.
* @param {string} path
*/
async goto(path = '/') {
await this.page.goto(path, { waitUntil: 'domcontentloaded' });
}
/**
* Returns the current page URL.
* @returns {string}
*/
getUrl() {
return this.page.url();
}
/**
* Returns page title.
* @returns {Promise<string>}
*/
async getTitle() {
return this.page.title();
}
/**
* Waits for a locator to be visible.
* @param {import('@playwright/test').Locator} locator
* @param {number} [timeout]
*/
async waitForVisible(locator, timeout) {
await locator.waitFor({ state: 'visible', timeout });
}
/**
* Resilient click that scrolls into view and handles potential intercepts.
* @param {import('@playwright/test').Locator} locator
*/
async safeClick(locator) {
await locator.scrollIntoViewIfNeeded();
await locator.click();
}
/**
* Checks whether the current URL contains the expected substring.
* @param {string} substring
*/
async expectUrlContains(substring) {
await expect(this.page).toHaveURL(new RegExp(substring));
}
/**
* Asserts document title.
* @param {string | RegExp} expectedTitle
*/
async expectTitle(expectedTitle) {
await expect(this.page).toHaveTitle(expectedTitle);
}
}
module.exports = { BasePage };
|