Skip to content

Commit

Permalink
FI-1512 fix: add tests for waitForAllRequestsComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 16, 2024
1 parent 6cac69f commit f7da93c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
8 changes: 4 additions & 4 deletions autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ export const pack: Pack = {
waitBeforeRetry: () => waitBeforeRetryTimeout,
waitForAllRequestsComplete: {
maxIntervalBetweenRequestsInMs: 500,
timeout: 30_000,
timeout: 15_000,
},
waitForInterfaceStabilization: {
stabilizationInterval: 500,
timeout: 30_000,
timeout: 15_000,
},
waitForRequestTimeout: 30_000,
waitForResponseTimeout: 30_000,
waitForRequestTimeout: 15_000,
waitForResponseTimeout: 15_000,
};
17 changes: 17 additions & 0 deletions autotests/pageObjects/pages/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Input} from 'autotests/pageObjects/components';
import {Main as MainRoute} from 'autotests/routes/pageRoutes';
import {createSelector} from 'autotests/selectors';
import {Page} from 'e2ed';
import {waitForAllRequestsComplete} from 'e2ed/actions';
import {setReadonlyProperty} from 'e2ed/utils';

import type {Language} from 'autotests/types';
Expand Down Expand Up @@ -59,4 +60,20 @@ export class Main extends Page<CustomPageParams> {
typeIntoSearchInput(text: string): Promise<void> {
return this.searchInput.type(text);
}

override async waitForPageLoaded(): Promise<void> {
await waitForAllRequestsComplete(
({url}) => {
if (
url.startsWith('https://play.google.com/') ||
url.startsWith('https://www.youtube.com/embed/')
) {
return false;
}

return true;
},
{maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs, timeout: 8_000},
);
}
}
21 changes: 21 additions & 0 deletions autotests/pageObjects/pages/Search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {MobilePage} from 'autotests/pageObjects';
import {Search as SearchRoute} from 'autotests/routes/pageRoutes';
import {waitForAllRequestsComplete} from 'e2ed/actions';
import {setReadonlyProperty} from 'e2ed/utils';

import type {GetParamsType} from 'e2ed/types';
Expand Down Expand Up @@ -32,4 +33,24 @@ export class Search extends MobilePage<CustomPageParams> {

setReadonlyProperty(this, 'searchQuery', searchQuery);
}

override async waitForPageLoaded(): Promise<void> {
await waitForAllRequestsComplete(
({url}) => {
if (
url.startsWith('https://encrypted-tbn0.gstatic.com/') ||
url.startsWith('https://www.google.com/gen_204?') ||
url.startsWith('https://lh5.googleusercontent.com/') ||
url.startsWith('https://play.google.com/') ||
url.startsWith('https://www.googleadservices.com/') ||
url.startsWith('https://www.youtube.com/embed/')
) {
return false;
}

return true;
},
{maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs, timeout: 8_000},
);
}
}
12 changes: 3 additions & 9 deletions autotests/tests/waitForAllRequestsComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import {test} from 'autotests';
import {getUsers} from 'autotests/entities';
import {waitForAllRequestsComplete} from 'e2ed/actions';
import {waitForAllRequestsComplete, waitForTimeout} from 'e2ed/actions';
import {assertFunctionThrows, E2edError} from 'e2ed/utils';

test(
'waitForAllRequestsComplete works correct with timeout and predicate in base cases',
{meta: {testId: '9'}, testIdleTimeout: 6_000},
// eslint-disable-next-line complexity, max-statements
async () => {
let startRequestInMs = Date.now();

Expand All @@ -30,10 +31,7 @@ test(

startRequestInMs = Date.now();

const promise = waitForAllRequestsComplete(() => true, {
maxIntervalBetweenRequestsInMs: 1500,
timeout: 1000,
});
let promise = waitForAllRequestsComplete(() => true, {timeout: 1000});

void getUsers(2);

Expand Down Expand Up @@ -66,8 +64,6 @@ test(
);
}

/*
promise = waitForAllRequestsComplete(() => true);

await getUsers(1);
Expand Down Expand Up @@ -103,7 +99,5 @@ test(
{waitedInMs},
);
}
*/
},
);
9 changes: 7 additions & 2 deletions src/Page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line import/no-internal-modules
/* eslint-disable import/no-internal-modules */

import {navigateToUrl} from './actions/navigateToUrl';
// eslint-disable-next-line import/no-internal-modules
import {waitForAllRequestsComplete} from './actions/waitFor/waitForAllRequestsComplete';
import {waitForStartOfPageLoad} from './actions/waitFor/waitForStartOfPageLoad';
import {CREATE_PAGE_TOKEN} from './constants/internal';
import {assertValueIsTrue} from './utils/asserts';
Expand Down Expand Up @@ -142,6 +143,10 @@ export abstract class Page<PageParams = undefined> {
*/
async waitForPageLoaded(): Promise<void> {
await this.waitForDomContentLoaded();

await waitForAllRequestsComplete(() => true, {
maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs,
});
}

/**
Expand Down

0 comments on commit f7da93c

Please sign in to comment.