Skip to content

Commit e8ee29e

Browse files
authored
Merge pull request #41 from joomcode/fix/error-in-interface-stabilization
fix: error in interface stabilization mechanism
2 parents 5a0a474 + e70c522 commit e8ee29e

29 files changed

+277
-95
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ If `null`, the report will not be saved.
323323
`skipTests: SkipTests`: this setting allows you to describe a set of skipped tests in a custom form.
324324
You can define the `SkipTests` type and `skipTests` processing rules in the hook `autotests/hooks/isTestSkipped.ts`.
325325

326-
`stabilizationInterval: number`: default stabilization interval for `waitForInterfaceStabilization` action.
327-
328326
`takeFullPageScreenshotOnError: boolean`: if `true`, then takes a screenshot of the full page
329327
(not just the viewport) at the time of the test error, for display in the HTML report.
330328

@@ -352,6 +350,12 @@ returned by the `waitForAllRequestsComplete` function will be successfully resol
352350
If the wait is longer than this timeout, then the promise
353351
returned by the `waitForAllRequestsComplete` function will be rejected.
354352

353+
`waitForInterfaceStabilization.stabilizationInterval: number`: default stabilization interval for `waitForInterfaceStabilization` function.
354+
355+
`waitForInterfaceStabilization.timeout: number`: default timeout (in milliseconds) for `waitForInterfaceStabilization` function.
356+
If the wait is longer than this timeout, then the promise
357+
returned by the `waitForInterfaceStabilization` function will be rejected.
358+
355359
`waitForRequestTimeout: number`: default timeout (in milliseconds) for `waitForRequest` function.
356360
If the wait is longer than this timeout, then the promise returned by the `waitForRequest` function will be rejected.
357361

autotests/configurator/skipTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {SkipTests} from 'autotests/types/skipTests';
55
*/
66
export const skipTests: SkipTests = [
77
{
8-
reason: 'Skip for testing skipping mechanism (with link [Google](https://google.com))',
8+
reason: 'Skip for testing skipping mechanism (with link to [Google](https://google.com))',
99
testIds: ['4'],
1010
unskipTaskUrl: 'https://tasktracker.com/3',
1111
},

autotests/packs/allTests.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const pack: Pack = {
4848
reportFileName: 'report.html',
4949
selectorTimeout: 10_000,
5050
skipTests,
51-
stabilizationInterval: 500,
5251
takeFullPageScreenshotOnError: false,
5352
takeViewportScreenshotOnError: true,
5453
testFileGlobs: ['./autotests/tests/**/*.ts', '!**/*.skip.ts'],
@@ -58,6 +57,10 @@ export const pack: Pack = {
5857
maxIntervalBetweenRequestsInMs: 500,
5958
timeout: 30_000,
6059
},
60+
waitForInterfaceStabilization: {
61+
stabilizationInterval: 500,
62+
timeout: 30_000,
63+
},
6164
waitForRequestTimeout: 30_000,
6265
waitForResponseTimeout: 30_000,
6366
};

autotests/packs/local.example.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ import type {Pack} from 'autotests/types/pack';
88
export const pack: Pack = {
99
...allTestsPack,
1010
browserInitTimeout: 40_000,
11+
dockerImage: 'e2edhub/e2ed',
1112
};

autotests/pageObjects/pages/Main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Main extends Page<CustomPageParams> {
5252
/**
5353
* Header selector.
5454
*/
55-
readonly headerSelector = mainPageLocator.header();
55+
readonly header = mainPageLocator.header();
5656

5757
/**
5858
* Search input.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-disable no-console */
2+
3+
import {it} from 'autotests';
4+
import {E2edReportExample} from 'autotests/pageObjects/pages';
5+
import {createClientFunction, expect} from 'e2ed';
6+
import {
7+
getBrowserConsoleMessages,
8+
getBrowserJsErrors,
9+
navigateToPage,
10+
setPageElementsIgnoredOnInterfaceStabilization,
11+
waitForInterfaceStabilization,
12+
} from 'e2ed/actions';
13+
14+
it('correctly read data from browser', {meta: {testId: '14'}}, async () => {
15+
await navigateToPage(E2edReportExample);
16+
17+
await setPageElementsIgnoredOnInterfaceStabilization(['.retry']);
18+
19+
await waitForInterfaceStabilization(100);
20+
21+
await createClientFunction(() => {
22+
console.error('error');
23+
console.info('info');
24+
console.log('log');
25+
console.warn('warn');
26+
27+
const key = Symbol.for('e2ed:PageElementsIgnoredOnInterfaceStabilization');
28+
const global = globalThis as {[key]?: readonly string[] | undefined};
29+
30+
console.log(global[key]);
31+
32+
setTimeout(() => {
33+
throw new Error('foo');
34+
}, 8);
35+
setTimeout(() => {
36+
throw new Error('bar');
37+
}, 32);
38+
})();
39+
40+
const {error, info, log, warn} = await getBrowserConsoleMessages();
41+
42+
await expect(
43+
error[0] === 'error' && info[0] === 'info' && log[0] === 'log' && warn[0] === 'warn',
44+
'`getBrowserConsoleMessages` read all of messages',
45+
).eql(true);
46+
47+
await expect(log[1], '`setPageElementsIgnoredOnInterfaceStabilization` works correct').eql(
48+
'.retry',
49+
);
50+
51+
const jsErrors = await getBrowserJsErrors();
52+
53+
await expect(
54+
jsErrors.length === 2 && jsErrors[0]?.message === 'foo' && jsErrors[1]?.message === 'bar',
55+
'`getBrowserJsErrors` read JS errors',
56+
).eql(true);
57+
});

autotests/tests/main/exists.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ it('exists', {meta: {testId: '1'}, testIdleTimeout: 35_000, testTimeout: 90_000}
3838

3939
const mainPage = await navigateToPage(Main, {language});
4040

41-
await expect(mainPage.pageParams, 'pageParams is correct after navigateToPage').eql({language});
41+
await expect(mainPage.pageParams, '`pageParams` is correct after `navigateToPage`').eql({
42+
language,
43+
});
4244

4345
await expect(mainPage.searchString, 'search string is empty').eql('');
4446

@@ -67,7 +69,9 @@ it('exists', {meta: {testId: '1'}, testIdleTimeout: 35_000, testTimeout: 90_000}
6769
* Do not use the following pageParams and url (by getParamsFromUrl) checks in your code.
6870
* These are e2ed internal checks. Use `assertPage` instead.
6971
*/
70-
await expect(searchPage.pageParams, 'pageParams is correct after assertPage').eql({searchQuery});
72+
await expect(searchPage.pageParams, '`pageParams` is correct after `assertPage`').eql({
73+
searchQuery,
74+
});
7175

7276
const url = await getDocumentUrl();
7377

src/actions/getBrowserConsoleMessages.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import {LogEventType} from '../constants/internal';
22
import {testController} from '../testController';
33
import {log} from '../utils/log';
44

5-
type ConsoleMessages = ReturnType<typeof testController.getBrowserConsoleMessages> extends Promise<
6-
infer Type
7-
>
8-
? Type
9-
: never;
5+
import type {UnwrapPromise} from '../types/internal';
6+
7+
type ConsoleMessages = UnwrapPromise<ReturnType<typeof testController.getBrowserConsoleMessages>>;
108

119
/**
1210
* Returns an object that contains messages output to the browser console.

src/actions/getBrowserJsErrors.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {LogEventType} from '../constants/internal';
2+
import {createClientFunction} from '../createClientFunction';
3+
import {log} from '../utils/log';
4+
5+
import type {BrowserJsError} from '../types/internal';
6+
7+
const clientGetBrowserJsErrors = createClientFunction(
8+
(): readonly BrowserJsError[] => {
9+
const key = Symbol.for('e2ed:JsErrors');
10+
const global = window as {[key]?: BrowserJsError[]};
11+
// eslint-disable-next-line no-multi-assign
12+
const errors = (global[key] ??= []);
13+
const copyOfErrors = [...errors];
14+
15+
errors.length = 0;
16+
17+
return copyOfErrors;
18+
},
19+
{name: 'getBrowserJsErrors'},
20+
);
21+
22+
/**
23+
* Get browser JS errors.
24+
*/
25+
export const getBrowserJsErrors = (): Promise<readonly BrowserJsError[]> => {
26+
log('Get browser JS errors', LogEventType.InternalAction);
27+
28+
return clientGetBrowserJsErrors();
29+
};

src/actions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export {doubleClick} from './doubleClick';
1515
export {drag} from './drag';
1616
export {dragToElement} from './dragToElement';
1717
export {getBrowserConsoleMessages} from './getBrowserConsoleMessages';
18+
export {getBrowserJsErrors} from './getBrowserJsErrors';
1819
export {getCookies} from './getCookies';
1920
export {hover} from './hover';
2021
export {mockApiRoute, unmockApiRoute} from './mock';
@@ -38,6 +39,7 @@ export {setCookies} from './setCookies';
3839
export {setFilesToUpload} from './setFilesToUpload';
3940
export {setHeadersAndNavigateToUrl} from './setHeadersAndNavigateToUrl';
4041
export {setNativeDialogHandler} from './setNativeDialogHandler';
42+
export {setPageElementsIgnoredOnInterfaceStabilization} from './setPageElementsIgnoredOnInterfaceStabilization';
4143
export {switchToIframe} from './switchToIframe';
4244
export {takeElementScreenshot} from './takeElementScreenshot';
4345
export {takeScreenshot} from './takeScreenshot';

0 commit comments

Comments
 (0)