Skip to content

Commit f0c991c

Browse files
authored
Merge pull request #117 from joomcode/fix/waitForRequest-context
feat: support switching tabs in all network actions
2 parents 076051b + 1cf42b8 commit f0c991c

60 files changed

Lines changed: 870 additions & 230 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ rules:
9090
- src/config.ts
9191
- src/createLocator.ts
9292
- src/getModulesGraph.ts
93-
- src/globby.ts
9493
- src/index.ts
9594
missingExports: true
9695
unusedExports: true
@@ -193,7 +192,7 @@ rules:
193192
'@typescript-eslint/no-loop-func': error
194193
'@typescript-eslint/no-magic-numbers':
195194
- error
196-
- ignore: [-2, -1, 0, 1, 2, 1024]
195+
- ignore: [-2, -1, 0, 1, 2, 1000, 1024]
197196
ignoreArrayIndexes: true
198197
ignoreDefaultValues: true
199198
ignoreEnums: true

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
- run: npm run build
4040
- run: npm run test:local
4141
- uses: actions/upload-artifact@v4
42+
if: ${{ always() }}
4243
with:
4344
name: reports
4445
path: build/autotests/reports

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ After the run, a detailed HTML report and a summary lite report in JSON format a
1818

1919
## Adding e2ed to a project
2020

21-
Prerequisites: [node](https://nodejs.org/en/) >=20,
21+
Prerequisites: [node](https://nodejs.org/en/) >=22,
2222
[TypeScript](https://www.typescriptlang.org/) >=5.
2323

2424
All commands below are run from the root directory of the project.
@@ -365,7 +365,7 @@ You can define the `SkipTests` type and `skipTests` processing rules in the hook
365365
at the time of the test error, for display in the HTML report.
366366

367367
`testFileGlobs: readonly string[]`: an array of globs with pack test (task) files.
368-
https://www.npmjs.com/package/globby is used for matching globs.
368+
`fs.glob` from `nodejs` is used for matching globs.
369369

370370
`testIdleTimeout: number`: timeout (in milliseconds) for each individual test step.
371371
If the test step (interval between two `log` function calls) takes longer than this timeout,

autotests/entities/device.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const createDevice = async ({
1616
cookies,
1717
input: 7,
1818
model,
19+
title: model,
1920
version,
2021
});
2122

autotests/entities/product.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import type {ClientFunction} from 'e2ed/types';
88
*/
99
export const addProduct: ClientFunction<[Product], Promise<ApiProduct>> = createClientFunction(
1010
(product: Product) =>
11-
fetch(`https://reqres.in/api/product/${product.id}?size=${product.size}`, {
11+
fetch(`https://dummyjson.com/products/add?id=${product.id}&size=${product.size}`, {
1212
body: JSON.stringify({
1313
cookies: [],
1414
input: product.input,
1515
model: product.model,
16+
title: product.model,
1617
version: product.version,
1718
}),
1819
headers: {'Content-Type': 'application/json; charset=UTF-8'},

autotests/entities/worker.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,52 @@ import {log} from 'e2ed/utils';
44
import type {UserWorker} from 'autotests/types';
55
import type {ClientFunction} from 'e2ed/types';
66

7-
const clientGetUsers = createClientFunction(
8-
(delay: number) =>
9-
fetch(`https://reqres.in/api/users?delay=${delay}`, {method: 'GET'}).then((res) => res.json()),
10-
{name: 'getUsers', timeout: 6_000},
11-
);
7+
type GetUsersOptions = Readonly<{delay?: number; retries?: number}> | undefined;
8+
9+
let clientGetUsers: ClientFunction<[number], unknown> | undefined;
10+
let clientGetUsersRetries: number | undefined;
1211

1312
/**
1413
* Adds user-worker.
1514
*/
16-
export const addUser: ClientFunction<[UserWorker, number?], Promise<object>> = createClientFunction(
17-
(user: UserWorker, delay?: number) =>
18-
fetch(`https://reqres.in/api/users${delay !== undefined ? `?delay=${delay}` : ''}`, {
15+
export const addUser: ClientFunction<
16+
[Readonly<{delay?: number; user: UserWorker}>],
17+
Promise<object>
18+
> = createClientFunction(
19+
({delay, user}) =>
20+
fetch(`https://dummyjson.com/users/add${delay !== undefined ? `?delay=${delay}` : ''}`, {
1921
body: JSON.stringify(user),
2022
headers: {'Content-Type': 'application/json; charset=UTF-8'},
2123
method: 'POST',
22-
}),
24+
})
25+
.then((res) => res.json())
26+
.then((result: UserWorker) => {
27+
// eslint-disable-next-line no-console
28+
console.log('addUser return', result);
29+
30+
return result;
31+
}),
32+
2333
{name: 'addUser', timeout: 3_000},
2434
);
2535

2636
/**
2737
* Get list of user-workers.
2838
*/
29-
export const getUsers = (delay: number): Promise<unknown> => {
39+
export const getUsers = ({delay = 0, retries = 0}: GetUsersOptions = {}): Promise<unknown> => {
3040
log(`Send API request with delay = ${delay}s`);
3141

42+
if (clientGetUsers === undefined || clientGetUsersRetries !== retries) {
43+
clientGetUsersRetries = retries;
44+
45+
clientGetUsers = createClientFunction(
46+
(clientDelay: number) =>
47+
fetch(`https://dummyjson.com/users?delay=${clientDelay}`, {method: 'GET'}).then(
48+
(res) => res.json() as unknown,
49+
),
50+
{name: 'getUsers', retries, timeout: 6_000},
51+
);
52+
}
53+
3254
return clientGetUsers(delay);
3355
};

autotests/fixtures/fullMocks/mr-iHTD7Lp.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"/products/add":[{"completionTimeInMs":1747533319483,"duration":"3ms","request":{"method":"POST","query":{"id":"135865","size":"13"},"requestBody":{"cookies":[],"input":17,"model":"samsung","title":"samsung","version":"12"},"requestHeaders":{"accept":"*/*","accept-language":"en-US","content-type":"application/json; charset=UTF-8","referer":"https://joomcode.github.io/","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36","sec-ch-ua":"\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"HeadlessChrome\";v=\"134\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"Linux\""},"url":"https://dummyjson.com/products/add?id=135865&size=13","utcTimeInMs":1747533319480},"responseBody":{"id":135865,"method":"POST","output":"17","payload":{"id":"135865","cookies":[],"input":17,"model":"samsung","title":"samsung","version":"12"},"query":{"id":"135865","size":"13"},"url":"https://dummyjson.com/products/add?id=135865&size=13"},"responseHeaders":{"content-type":"application/json; charset=UTF-8","content-length":"241"},"statusCode":200},{"completionTimeInMs":1747533319780,"duration":"3ms","request":{"method":"POST","query":{"id":"135865","size":"13"},"requestBody":{"cookies":[],"input":17,"model":"samsung","title":"samsung","version":"12"},"requestHeaders":{"accept":"*/*","accept-language":"en-US","content-type":"application/json; charset=UTF-8","referer":"https://joomcode.github.io/","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36","sec-ch-ua":"\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"HeadlessChrome\";v=\"134\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"Linux\""},"url":"https://dummyjson.com/products/add?id=135865&size=13","utcTimeInMs":1747533319777},"responseBody":{"id":195,"title":"samsung"},"responseHeaders":{"etag":"W/\"1c-hP2nNXEenyGq06xPgJ9a0RJCH9E\"","x-content-type-options":"nosniff","date":"Sun, 18 May 2025 01:55:19 GMT","content-type":"application/json; charset=utf-8","vary":"Accept-Encoding","x-frame-options":"SAMEORIGIN","strict-transport-security":"max-age=15552000; includeSubDomains","x-dns-prefetch-control":"off","x-ratelimit-reset":"1747533329","x-download-options":"noopen","x-ratelimit-remaining":"99","access-control-allow-origin":"*","content-length":"28","x-xss-protection":"1; mode=block","x-ratelimit-limit":"100","x-railway-request-id":"cHuLc3G1SFSKT7u4m3z_FQ","x-powered-by":"Cats on Keyboards","x-railway-edge":"railway/europe-west4-drams3a","server":"railway-edge"},"statusCode":201}]}

autotests/pageObjects/pages/E2edReportExample/E2edReportExample.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from 'autotests/actions';
55
import {setPageCookies, setPageRequestHeaders} from 'autotests/context';
66
import {E2edReportExample as E2edReportExampleRoute} from 'autotests/routes/pageRoutes';
7-
import {createSelector, locator} from 'autotests/selectors';
7+
import {locator} from 'autotests/selectors';
88
import {Page} from 'e2ed';
99
import {setReadonlyProperty} from 'e2ed/utils';
1010

@@ -23,7 +23,7 @@ export class E2edReportExample extends Page<CustomPageParams> {
2323
/**
2424
* Page header.
2525
*/
26-
readonly header: Selector = createSelector('.header');
26+
readonly header: Selector = locator('header');
2727

2828
/**
2929
* Navigation bar with test retries.

autotests/pageObjects/pages/Main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export class Main extends Page<CustomPageParams> {
6767
await waitForAllRequestsComplete(
6868
({url}) => {
6969
if (
70+
url.startsWith('https://browser.events.data.msn.com/') ||
7071
url.startsWith('https://img-s-msn-com.akamaized.net/') ||
72+
url.startsWith('https://rewards.bing.com/widget/') ||
7173
url.startsWith('https://www.bing.com/th?id=')
7274
) {
7375
return false;

0 commit comments

Comments
 (0)