e2ed
Version:
E2E testing framework over Playwright
33 lines (32 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForStartOfPageLoad = void 0;
const useContext_1 = require("../../useContext");
const asserts_1 = require("../../utils/asserts");
const config_1 = require("../../utils/config");
const getDurationWithUnits_1 = require("../../utils/getDurationWithUnits");
const log_1 = require("../../utils/log");
/**
* Waits for start of page load (when change the url or reload page).
*/
const waitForStartOfPageLoad = async (options) => {
const startTimeInMs = Date.now();
const page = (0, useContext_1.getPlaywrightPage)();
const timeout = options?.timeout ?? (0, config_1.getFullPackConfig)().navigationTimeout;
let urlObject;
let wasCalled = false;
await page.waitForURL((url) => {
if (wasCalled === false) {
wasCalled = true;
return false;
}
urlObject = url;
return true;
}, { timeout, waitUntil: 'commit' });
(0, asserts_1.assertValueIsDefined)(urlObject, 'urlObject is defined', { timeout });
const waitInMs = Date.now() - startTimeInMs;
const waitWithUnits = (0, getDurationWithUnits_1.getDurationWithUnits)(waitInMs);
(0, log_1.log)(`Have waited for start of page load for ${waitWithUnits} at ${urlObject.href}`, 5 /* LogEventType.InternalAction */);
return urlObject;
};
exports.waitForStartOfPageLoad = waitForStartOfPageLoad;