Skip to content

Commit

Permalink
FI-1434 feat: add action waitForStartOfPageLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 7, 2024
1 parent 460df00 commit 90e2d77
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const pack: Pack = {
maxRetriesCountInDocker: 3,
overriddenConfigFields: null,
packTimeout: packTimeoutInMinutes * msInMinute,
pageRequestTimeout: 30_000,
pageRequestTimeout: 7_000,
pageStabilizationInterval: 500,
pathToScreenshotsDirectoryForReport: './screenshots',
port1: 1337,
Expand Down
10 changes: 8 additions & 2 deletions src/Page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// eslint-disable-next-line import/no-internal-modules
import {navigateToUrl} from './actions/navigateToUrl';
// eslint-disable-next-line import/no-internal-modules
import {waitForStartOfPageLoad} from './actions/waitFor/waitForStartOfPageLoad';
import {CREATE_PAGE_TOKEN} from './constants/internal';
import {assertValueIsTrue} from './utils/asserts';
import {getFullPackConfig} from './utils/config';
Expand Down Expand Up @@ -118,8 +120,12 @@ export abstract class Page<PageParams = undefined> {
/**
* Reloads the page.
*/
reloadPage(): Promise<void> {
return reloadDocument();
async reloadPage(): Promise<void> {
const startOfPageLoad = waitForStartOfPageLoad();

await reloadDocument();

await startOfPageLoad;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export {
waitForRequestToRoute,
waitForResponse,
waitForResponseToRoute,
waitForStartOfPageLoad,
waitForTimeout,
} from './waitFor';
1 change: 1 addition & 0 deletions src/actions/waitFor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export {waitForRequest} from './waitForRequest';
export {waitForRequestToRoute} from './waitForRequestToRoute';
export {waitForResponse} from './waitForResponse';
export {waitForResponseToRoute} from './waitForResponseToRoute';
export {waitForStartOfPageLoad} from './waitForStartOfPageLoad';
export {waitForTimeout} from './waitForTimeout';
30 changes: 30 additions & 0 deletions src/actions/waitFor/waitForStartOfPageLoad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {getPlaywrightPage} from '../../useContext';
import {assertValueIsDefined} from '../../utils/asserts';
import {getFullPackConfig} from '../../utils/config';

type Options = Readonly<{
timeout?: number;
}>;

/**
* Waits for start of page load (when change the url or reload page).
*/
export const waitForStartOfPageLoad = async (options?: Options): Promise<URL> => {
const page = getPlaywrightPage();
const timeout = options?.timeout ?? getFullPackConfig().pageRequestTimeout;

let urlObject: URL | undefined;

await page.waitForURL(
(url) => {
urlObject = url;

return true;
},
{timeout},
);

assertValueIsDefined(urlObject, 'urlObject is defined', {timeout});

return urlObject;
};

0 comments on commit 90e2d77

Please sign in to comment.