From 6d46fae75522f013d3227e368c6b508bdeb2687e Mon Sep 17 00:00:00 2001 From: Siarhei Yelin Date: Tue, 30 Jul 2024 18:14:34 +0300 Subject: [PATCH] Fix csp err --- .../framework/fixtures/shared/absPage.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/uui-e2e-tests/framework/fixtures/shared/absPage.ts b/uui-e2e-tests/framework/fixtures/shared/absPage.ts index 1f26e7e218..127da36a1a 100644 --- a/uui-e2e-tests/framework/fixtures/shared/absPage.ts +++ b/uui-e2e-tests/framework/fixtures/shared/absPage.ts @@ -41,13 +41,6 @@ export abstract class AbsPage { if (this.extraStyles) { await this.page.addStyleTag({ path: this.extraStyles }); } - /** - * We must wait for this global variable to be able to run our tests - */ - await this.page.waitForFunction((name) => { - // @ts-ignore Reason: this specific code will be run in context of web page - return !!window[name]; - }, PlayWrightInterfaceName); } async focusElement(selector: string) { @@ -76,10 +69,22 @@ export abstract class AbsPage { protected async _clientRedirect(params: T) { await this.page.mouse.move(0, 0); - await this.page.evaluate((_params: string) => { + await this.page.evaluate(async (_params: string) => { const [p, i] = _params.split('[||||]'); // @ts-ignore Reason: this specific code will be run in context of web page - (window as any)[i](p); + const globalObj = window as any; + const waitForInterface = () => { + return new Promise((resolve) => { + const get = () => globalObj[i]; + const _intervalId = globalObj.setInterval(() => { + if (get()) { + globalObj.clearInterval(_intervalId); + resolve(get()); + } + }, 300); + }); + }; + (await waitForInterface())(p); }, [jsonStringify(params), PlayWrightInterfaceName].join('[||||]')); } }