Skip to content

Commit 62163fd

Browse files
authored
Merge pull request #127 from joomcode/fix/reload-page-timeout
fix: reload page timeout
2 parents 11ac677 + 7f6fca6 commit 62163fd

27 files changed

+384
-125
lines changed

autotests/actions/setPageCookiesAndNavigateToUrl.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import {getHeaderValue, log, replaceSetCookie} from 'e2ed/utils';
44

55
import type {Cookie, NavigationReturn, SetCookieHeaderString, StringHeaders, Url} from 'e2ed/types';
66

7+
type Options = Readonly<{
8+
pageCookies: readonly Cookie[];
9+
timeout?: number;
10+
}>;
11+
712
/**
813
* Navigates to the url and set custom page cookies.
914
*/
1015
export const setPageCookiesAndNavigateToUrl = (
1116
url: Url,
12-
pageCookies: readonly Cookie[],
17+
{pageCookies, timeout}: Options,
1318
): Promise<NavigationReturn> => {
1419
const mapResponseHeaders = (headers: StringHeaders): StringHeaders => {
1520
const setCookies = getHeaderValue(headers, 'set-cookie');
@@ -28,5 +33,9 @@ export const setPageCookiesAndNavigateToUrl = (
2833

2934
log(`Navigate to ${url} and set page cookie`, {pageCookies, url}, LogEventType.Action);
3035

31-
return setHeadersAndNavigateToUrl(url, {mapResponseHeaders});
36+
return setHeadersAndNavigateToUrl(
37+
url,
38+
{mapResponseHeaders},
39+
timeout !== undefined ? {timeout} : undefined,
40+
);
3241
};

autotests/actions/setPageRequestHeadersAndNavigateToUrl.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import {log} from 'e2ed/utils';
44

55
import type {NavigationReturn, StringHeaders, Url} from 'e2ed/types';
66

7+
type Options = Readonly<{
8+
pageRequestHeaders: StringHeaders;
9+
timeout?: number;
10+
}>;
11+
712
/**
813
* Navigates to the url and set additional page request headers.
914
*/
1015
export const setPageRequestHeadersAndNavigateToUrl = (
1116
url: Url,
12-
pageRequestHeaders: StringHeaders,
17+
{pageRequestHeaders, timeout}: Options,
1318
): Promise<NavigationReturn> => {
1419
const mapRequestHeaders = (): StringHeaders => pageRequestHeaders;
1520

@@ -19,5 +24,9 @@ export const setPageRequestHeadersAndNavigateToUrl = (
1924
LogEventType.Action,
2025
);
2126

22-
return setHeadersAndNavigateToUrl(url, {mapRequestHeaders});
27+
return setHeadersAndNavigateToUrl(
28+
url,
29+
{mapRequestHeaders},
30+
timeout !== undefined ? {timeout} : undefined,
31+
);
2332
};

autotests/configurator/regroupSteps.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import type {LogEvent, Mutable} from 'e2ed/types';
55

66
/**
77
* Regroup log events (for grouping of `TestRun` steps).
8-
* This base client function should not use scope variables (except other base functions).
9-
* @internal
108
*/
119
export const regroupSteps = (logEvents: readonly LogEvent[]): readonly LogEvent[] => {
1210
const topLevelTypes: readonly LogEventType[] = [

autotests/pageObjects/pages/E2edReportExample/E2edReportExample.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,16 @@ export class E2edReportExample extends Page<CustomPageParams> {
122122

123123
override navigateToPage(url: Url): Promise<NavigationReturn> {
124124
if (this.pageRequestHeaders) {
125-
return setPageRequestHeadersAndNavigateToUrl(url, this.pageRequestHeaders);
125+
return setPageRequestHeadersAndNavigateToUrl(url, {
126+
pageRequestHeaders: this.pageRequestHeaders,
127+
timeout: E2edReportExample.navigationTimeout,
128+
});
126129
}
127130

128-
return setPageCookiesAndNavigateToUrl(url, this.pageCookies);
131+
return setPageCookiesAndNavigateToUrl(url, {
132+
pageCookies: this.pageCookies,
133+
timeout: E2edReportExample.navigationTimeout,
134+
});
129135
}
130136

131137
override async waitForPageLoaded(): Promise<void> {

autotests/tests/main/exists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {assertFunctionThrows, getDocumentUrl} from 'e2ed/utils';
2020
import type {Url} from 'e2ed/types';
2121

2222
// eslint-disable-next-line max-statements
23-
test('exists', {meta: {testId: '1'}, testIdleTimeout: 10_000, testTimeout: 20_000}, async () => {
23+
test('exists', {meta: {testId: '1'}, testIdleTimeout: 12_000, testTimeout: 20_000}, async () => {
2424
const language = 'en';
2525
const searchQuery = 'foo';
2626
const testScrollValue = 200;

src/Page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export abstract class Page<PageParams = undefined> {
167167

168168
await waitForAllRequestsComplete(() => true, {
169169
maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs,
170+
timeout: (this.constructor as typeof Page).navigationTimeout,
170171
});
171172
}
172173

src/README.md

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,44 @@ Modules in the dependency graph should only import the modules above them:
1515
8. `utils/getHash`
1616
9. `generators`
1717
10. `utils/headers`
18-
11. `utils/viewport`
19-
12. `utils/parse`
20-
13. `utils/distanceBetweenSelectors`
21-
14. `utils/getDurationWithUnits`
22-
15. `utils/valueToString`
23-
16. `utils/error`
24-
17. `utils/asserts`
25-
18. `utils/object`
26-
19. `utils/uiMode`
27-
20. `utils/runLabel`
28-
21. `utils/clone`
29-
22. `utils/notIncludedInPackTests`
30-
23. `utils/userland`
31-
24. `utils/fn`
32-
25. `utils/environment`
33-
26. `utils/packCompiler`
34-
27. `config`
35-
28. `utils/config`
36-
29. `utils/generalLog`
37-
30. `utils/testFilePaths`
38-
31. `utils/exit`
39-
32. `utils/promise`
40-
33. `utils/resourceUsage`
41-
34. `utils/fs`
42-
35. `utils/getGlobalErrorHandler`
43-
36. `utils/tests`
44-
37. `utils/end`
45-
38. `utils/pack`
46-
39. `useContext`
47-
40. `context`
48-
41. `utils/step`
49-
42. `utils/apiStatistics`
50-
43. `utils/selectors`
51-
44. `selectors`
52-
45. `utils/log`
53-
46. `step`
54-
47. `utils/waitForEvents`
55-
48. `utils/expect`
56-
49. `expect`
57-
50. ...
18+
11. `utils/screenshot`
19+
12. `utils/viewport`
20+
13. `utils/parse`
21+
14. `utils/distanceBetweenSelectors`
22+
15. `utils/getDurationWithUnits`
23+
16. `utils/valueToString`
24+
17. `utils/error`
25+
18. `utils/asserts`
26+
19. `utils/object`
27+
20. `utils/uiMode`
28+
21. `utils/runLabel`
29+
22. `utils/clone`
30+
23. `utils/notIncludedInPackTests`
31+
24. `utils/userland`
32+
25. `utils/fn`
33+
26. `utils/environment`
34+
27. `utils/packCompiler`
35+
28. `config`
36+
29. `utils/config`
37+
30. `utils/generalLog`
38+
31. `utils/testFilePaths`
39+
32. `utils/exit`
40+
33. `utils/promise`
41+
34. `utils/resourceUsage`
42+
35. `utils/fs`
43+
36. `utils/getGlobalErrorHandler`
44+
37. `utils/tests`
45+
38. `utils/end`
46+
39. `utils/pack`
47+
40. `useContext`
48+
41. `context`
49+
42. `utils/step`
50+
43. `utils/apiStatistics`
51+
44. `utils/selectors`
52+
45. `selectors`
53+
46. `utils/log`
54+
47. `step`
55+
48. `utils/waitForEvents`
56+
49. `utils/expect`
57+
50. `expect`
58+
51. ...

src/actions/pages/reloadPage.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {LogEventType} from '../../constants/internal';
1+
import {ADDITIONAL_STEP_TIMEOUT, LogEventType} from '../../constants/internal';
22
import {step} from '../../step';
33

44
import type {AnyPageClassType} from '../../types/internal';
@@ -18,5 +18,8 @@ export const reloadPage = (page: InstanceType<AnyPageClassType>): Promise<void>
1818

1919
await page.afterReloadPage?.();
2020
},
21-
{type: LogEventType.InternalAction},
21+
{
22+
timeout: (page.constructor as AnyPageClassType).navigationTimeout + ADDITIONAL_STEP_TIMEOUT,
23+
type: LogEventType.InternalAction,
24+
},
2225
);

src/actions/takeElementScreenshot.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import {join} from 'node:path';
22

3-
import {LogEventType, SCREENSHOTS_DIRECTORY_PATH} from '../constants/internal';
3+
import {
4+
ADDITIONAL_STEP_TIMEOUT,
5+
LogEventType,
6+
SCREENSHOTS_DIRECTORY_PATH,
7+
} from '../constants/internal';
48
import {step} from '../step';
9+
import {getDimensionsString, getPngDimensions} from '../utils/screenshot';
510

611
import type {Locator} from '@playwright/test';
712

@@ -17,6 +22,7 @@ export const takeElementScreenshot = async (
1722
options: Options = {},
1823
): Promise<void> => {
1924
const {path: pathToScreenshot, ...optionsWithoutPath} = options;
25+
const {timeout} = options;
2026

2127
await step(
2228
'Take a screenshot of the element',
@@ -26,10 +32,14 @@ export const takeElementScreenshot = async (
2632
options.path = join(SCREENSHOTS_DIRECTORY_PATH, pathToScreenshot);
2733
}
2834

29-
await selector.getPlaywrightLocator().screenshot(options);
35+
const screenshot = await selector.getPlaywrightLocator().screenshot(options);
36+
const dimensions = getDimensionsString(getPngDimensions(screenshot));
37+
38+
return {dimensions};
3039
},
3140
{
3241
payload: {pathToScreenshot, ...optionsWithoutPath, selector},
42+
...(timeout !== undefined ? {timeout: timeout + ADDITIONAL_STEP_TIMEOUT} : undefined),
3343
type: LogEventType.InternalAction,
3444
},
3545
);

src/actions/takeScreenshot.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import {join} from 'node:path';
22

3-
import {LogEventType, SCREENSHOTS_DIRECTORY_PATH} from '../constants/internal';
3+
import {
4+
ADDITIONAL_STEP_TIMEOUT,
5+
LogEventType,
6+
SCREENSHOTS_DIRECTORY_PATH,
7+
} from '../constants/internal';
48
import {step} from '../step';
59
import {getPlaywrightPage} from '../useContext';
10+
import {getDimensionsString, getPngDimensions} from '../utils/screenshot';
611

712
import type {Page} from '@playwright/test';
813

@@ -13,6 +18,7 @@ type Options = Parameters<Page['screenshot']>[0];
1318
*/
1419
export const takeScreenshot = async (options: Options = {}): Promise<void> => {
1520
const {path: pathToScreenshot, ...optionsWithoutPath} = options;
21+
const {timeout} = options;
1622

1723
await step(
1824
'Take a screenshot of the page',
@@ -24,8 +30,15 @@ export const takeScreenshot = async (options: Options = {}): Promise<void> => {
2430

2531
const page = getPlaywrightPage();
2632

27-
await page.screenshot(options);
33+
const screenshot = await page.screenshot(options);
34+
const dimensions = getDimensionsString(getPngDimensions(screenshot));
35+
36+
return {dimensions};
37+
},
38+
{
39+
payload: {pathToScreenshot, ...optionsWithoutPath},
40+
...(timeout !== undefined ? {timeout: timeout + ADDITIONAL_STEP_TIMEOUT} : undefined),
41+
type: LogEventType.InternalAction,
2842
},
29-
{payload: {pathToScreenshot, ...optionsWithoutPath}, type: LogEventType.InternalAction},
3043
);
3144
};

0 commit comments

Comments
 (0)