e2ed
Version:
E2E testing framework over Playwright
88 lines (87 loc) • 3.46 kB
JavaScript
;
/* eslint-disable import/no-internal-modules */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Page = void 0;
const navigateToUrl_1 = require("./actions/navigateToUrl");
const waitForAllRequestsComplete_1 = require("./actions/waitFor/waitForAllRequestsComplete");
const waitForStartOfPageLoad_1 = require("./actions/waitFor/waitForStartOfPageLoad");
const internal_1 = require("./constants/internal");
const asserts_1 = require("./utils/asserts");
const config_1 = require("./utils/config");
const document_1 = require("./utils/document");
const useContext_1 = require("./useContext");
/**
* Abstract page with base methods.
*/
class Page {
/**
* Default maximum interval (in milliseconds) between requests.
* After navigating to the page, `e2ed` will wait until
* all requests will complete, and only after that it will consider the page loaded.
* If there are no new requests for more than this interval,
* then we will consider that all requests completes
* The default value is taken from the corresponding field of the pack config.
*/
maxIntervalBetweenRequestsInMs;
/**
* Default timeout for navigation to url (`navigateToPage`, `navigateToUrl` actions) in milliseconds.
* The default value is taken from the corresponding field of the pack config.
*/
navigationTimeout;
/**
* Immutable page parameters.
*/
pageParams;
constructor(...args) {
const [createPageToken, pageParams] = args;
(0, asserts_1.assertValueIsTrue)(createPageToken === internal_1.CREATE_PAGE_TOKEN, 'createPageToken is correct', {
createPageToken,
pageParams,
});
this.pageParams = pageParams;
const { navigationTimeout, waitForAllRequestsComplete: { maxIntervalBetweenRequestsInMs }, } = (0, config_1.getFullPackConfig)();
this.maxIntervalBetweenRequestsInMs = maxIntervalBetweenRequestsInMs;
this.navigationTimeout = navigationTimeout;
}
/**
* Asserts that we are on the expected page by `isMatch` flage.
* `isMatch` equals `true`, if url matches the page with given parameters, and `false` otherwise.
*/
assertPage(isMatch, documentUrl) {
(0, asserts_1.assertValueIsTrue)(isMatch, `the document url matches the page "${this.constructor.name}"`, {
documentUrl,
page: this,
});
}
/**
* Navigates to the page by url.
*/
navigateToPage(url, options) {
return (0, navigateToUrl_1.navigateToUrl)(url, { skipLogs: true, timeout: this.navigationTimeout, ...options });
}
/**
* Reloads the page.
*/
async reloadPage() {
const startOfPageLoad = (0, waitForStartOfPageLoad_1.waitForStartOfPageLoad)();
await (0, document_1.reloadDocument)();
await startOfPageLoad;
}
/**
* Waits for `DOMContentLoaded` event.
*/
async waitForDomContentLoaded() {
const playwrightPage = (0, useContext_1.getPlaywrightPage)();
await playwrightPage.waitForLoadState('domcontentloaded');
}
/**
* Waits for page loaded.
*/
async waitForPageLoaded() {
await this.waitForDomContentLoaded();
await (0, waitForAllRequestsComplete_1.waitForAllRequestsComplete)(() => true, {
maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs,
});
}
}
exports.Page = Page;