From 3bdebbcbce14c0fd8b3db2c3845120608155be91 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 1 Feb 2024 20:57:31 +0100 Subject: [PATCH] feat: Perform device init steps in parallel (#912) --- lib/commands/device/common.js | 54 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/commands/device/common.js b/lib/commands/device/common.js index cfcdf3cb..7485d468 100644 --- a/lib/commands/device/common.js +++ b/lib/commands/device/common.js @@ -1,5 +1,6 @@ import semver from 'semver'; import _ from 'lodash'; +import B from 'bluebird'; import {resetMockLocation, setMockLocationApp} from '../geolocation'; import {SETTINGS_HELPER_ID} from 'io.appium.settings'; import {hideKeyboardCompletely, initUnicodeKeyboard} from '../keyboard'; @@ -177,7 +178,7 @@ export async function getLaunchInfo() { /** * @this {AndroidDriver} - * @returns + * @returns {Promise} */ export async function initDevice() { const { @@ -220,40 +221,47 @@ export async function initDevice() { await pushSettingsApp.bind(this)(shouldThrowError); } + /** @type {Promise[]} */ + const promises = []; + if (!this.isEmulator()) { - if (mockLocationApp || _.isUndefined(mockLocationApp)) { - await setMockLocationApp.bind(this)(mockLocationApp || SETTINGS_HELPER_ID); - } else { - await resetMockLocation.bind(this)(); - } + promises.push((async () => { + if (mockLocationApp || _.isUndefined(mockLocationApp)) { + await setMockLocationApp.bind(this)(mockLocationApp || SETTINGS_HELPER_ID); + } else { + await resetMockLocation.bind(this)(); + } + })()); } - if (language && locale) { - await this.ensureDeviceLocale(language, locale, localeScript); + promises.push(this.ensureDeviceLocale(language, locale, localeScript)); } - if (skipLogcatCapture) { this.log.info(`'skipLogcatCapture' is set. Skipping starting logcat capture.`); } else { - await this.adb.startLogcat({ + promises.push(this.adb.startLogcat({ format: logcatFormat, filterSpecs: logcatFilterSpecs, - }); + })); } - - if (hideKeyboard) { - await hideKeyboardCompletely.bind(this)(); - } else if (hideKeyboard === false) { - await this.adb.shell(['ime', 'reset']); - } - + promises.push((async () => { + if (hideKeyboard) { + await hideKeyboardCompletely.bind(this)(); + } else if (hideKeyboard === false) { + await this.adb.shell(['ime', 'reset']); + } + })()); if (unicodeKeyboard) { - this.log.warn( - `The 'unicodeKeyboard' capability has been deprecated and will be removed. ` + - `Set the 'hideKeyboard' capability to 'true' in order to make the on-screen keyboard invisible.`, - ); - return await initUnicodeKeyboard.bind(this)(); + promises.push((async () => { + this.log.warn( + `The 'unicodeKeyboard' capability has been deprecated and will be removed. ` + + `Set the 'hideKeyboard' capability to 'true' in order to make the on-screen keyboard invisible.`, + ); + await initUnicodeKeyboard.bind(this)(); + })()); } + + await B.all(promises); } /**