diff --git a/test/functional/services/common/browser.ts b/test/functional/services/common/browser.ts index 93deeda19eee9..e809a0d69f7b6 100644 --- a/test/functional/services/common/browser.ts +++ b/test/functional/services/common/browser.ts @@ -477,11 +477,27 @@ export async function BrowserProvider({ getService }: FtrProviderContext) { ); } - public async executeAsync( - fn: string | ((...args: any[]) => Promise), + public async executeAsync(fn: (cb: (value?: T) => void) => void): Promise; + public async executeAsync( + fn: (a1: A1, cb: (value?: T) => void) => void, + a1: A1 + ): Promise; + public async executeAsync( + fn: (a1: A1, a2: A2, cb: (value?: T) => void) => void, + a1: A1, + a2: A2 + ): Promise; + public async executeAsync( + fn: (a1: A1, a2: A2, a3: A3, cb: (value?: T) => void) => void, + a1: A1, + a2: A2, + a3: A3 + ): Promise; + public async executeAsync( + fn: (...args: any[]) => void, ...args: any[] - ): Promise { - return await driver.executeAsyncScript( + ): Promise { + return await driver.executeAsyncScript( fn, ...cloneDeep(args, (arg) => { if (arg instanceof WebElementWrapper) { diff --git a/test/interpreter_functional/test_suites/run_pipeline/helpers.ts b/test/interpreter_functional/test_suites/run_pipeline/helpers.ts index 2486fb0e1fbd0..bbf45b003c330 100644 --- a/test/interpreter_functional/test_suites/run_pipeline/helpers.ts +++ b/test/interpreter_functional/test_suites/run_pipeline/helpers.ts @@ -110,13 +110,13 @@ export function expectExpressionProvider({ stepContext: ExpressionValue = context ): Promise => { log.debug(`running expression ${step || expression}`); - return browser.executeAsync( - ( - _expression: string, - _currentContext: ExpressionValue & { type: string }, - _initialContext: ExpressionValue, - done: (expressionResult: ExpressionResult) => void - ) => { + return browser.executeAsync< + ExpressionResult, + string, + ExpressionValue & { type: string }, + ExpressionValue + >( + (_expression, _currentContext, _initialContext, done) => { if (!_currentContext) _currentContext = { type: 'null' }; if (!_currentContext.type) _currentContext.type = 'null'; return window diff --git a/test/plugin_functional/test_suites/application_links/redirect_app_links.ts b/test/plugin_functional/test_suites/application_links/redirect_app_links.ts index 54f7cdf1fdff5..9120018958bda 100644 --- a/test/plugin_functional/test_suites/application_links/redirect_app_links.ts +++ b/test/plugin_functional/test_suites/application_links/redirect_app_links.ts @@ -40,16 +40,15 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide const testSubjects = getService('testSubjects'); const setNonReloadedFlag = () => { - return browser.executeAsync(async (cb: Function) => { + return browser.executeAsync(async (cb) => { window.__nonReloadedFlag = true; cb(); }); }; - const wasReloaded = (): Promise => { + const wasReloaded = () => { return browser.executeAsync(async (cb) => { const reloaded = window.__nonReloadedFlag !== true; cb(reloaded); - return reloaded; }); }; diff --git a/test/plugin_functional/test_suites/core_plugins/application_status.ts b/test/plugin_functional/test_suites/core_plugins/application_status.ts index 96bcda39f3981..31a1c28b50842 100644 --- a/test/plugin_functional/test_suites/core_plugins/application_status.ts +++ b/test/plugin_functional/test_suites/core_plugins/application_status.ts @@ -44,17 +44,17 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide const testSubjects = getService('testSubjects'); const setAppStatus = async (s: Partial) => { - return browser.executeAsync(async (status: Partial, cb: Function) => { + return browser.executeAsync(async (status, cb) => { window.__coreAppStatus.setAppStatus(status); cb(); }, s); }; const navigateToApp = async (i: string) => { - return (await browser.executeAsync(async (appId, cb: Function) => { + return await browser.executeAsync(async (appId, cb) => { await window.__coreAppStatus.navigateToApp(appId); cb(); - }, i)) as any; + }, i); }; // FLAKY: https://github.com/elastic/kibana/issues/65423 diff --git a/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts b/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts index 929d5b68be93d..3a27be42a2a42 100644 --- a/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts +++ b/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts @@ -49,7 +49,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide it('to start services via coreSetup.getStartServices', async () => { expect( - await browser.executeAsync(async (cb) => { + await browser.executeAsync(async (cb) => { const [coreStart] = await window.__coreProvider.setup.core.getStartServices(); cb(Boolean(coreStart.overlays)); }) diff --git a/test/plugin_functional/test_suites/core_plugins/ui_settings.ts b/test/plugin_functional/test_suites/core_plugins/ui_settings.ts index 6a0a5fed48e6d..3a618ceaeb22f 100644 --- a/test/plugin_functional/test_suites/core_plugins/ui_settings.ts +++ b/test/plugin_functional/test_suites/core_plugins/ui_settings.ts @@ -49,7 +49,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide expect(settingsValue).to.be('2'); - const settingsValueViaObservables = await browser.executeAsync(async (callback: Function) => { + const settingsValueViaObservables = await browser.executeAsync(async (callback) => { window.__coreProvider.setup.core.uiSettings .get$('ui_settings_plugin') .subscribe((v) => callback(v)); diff --git a/x-pack/test/licensing_plugin/public/updates.ts b/x-pack/test/licensing_plugin/public/updates.ts index 4914513193cb4..4604cfe032b0b 100644 --- a/x-pack/test/licensing_plugin/public/updates.ts +++ b/x-pack/test/licensing_plugin/public/updates.ts @@ -27,7 +27,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch @@ -43,7 +43,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch @@ -59,7 +59,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch @@ -75,7 +75,7 @@ export default function (ftrContext: FtrProviderContext) { await scenario.waitForPluginToDetectLicenseUpdate(); expect( - await browser.executeAsync(async (cb: Function) => { + await browser.executeAsync(async (cb) => { const { setup, testUtils } = window.__coreProvider; // this call enforces signature check to detect license update // and causes license re-fetch diff --git a/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts b/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts index 4cc056fd51c2a..ee1745436b735 100644 --- a/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts +++ b/x-pack/test/plugin_functional/test_suites/global_search/global_search_api.ts @@ -14,13 +14,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { const browser = getService('browser'); const findResultsWithAPI = async (t: string): Promise => { - return browser.executeAsync(async (term: string, cb: Function) => { + return browser.executeAsync(async (term, cb) => { const { start } = window.__coreProvider; const globalSearchTestApi: GlobalSearchTestApi = start.plugins.globalSearchTest; - globalSearchTestApi.findAll(term).then((results) => { - cb(results); - }); - }, t) as any; // executeAsync signature is broken. return type should be inferred from the cb param. + globalSearchTestApi.findAll(term).then(cb); + }, t); }; describe('GlobalSearch API', function () {