From ee8c46aa23e90974e66a108dc5aee6a578d10f55 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 30 Oct 2023 18:42:53 +0100 Subject: [PATCH] feat: Add 'hideKeyboard' capability --- README.md | 1 + lib/driver.js | 14 +++++++++++++- package.json | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e28dd6f8..1e178a8e 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ appium:buildToolsVersion | The version of Android build tools to use. By default appium:skipLogcatCapture | Being set to `true` disables automatic logcat output collection during the test run. `false` by default appium:suppressKillServer | Being set to `true` prevents the driver from ever killing the ADB server explicitly. Could be useful if ADB is connected wirelessly. `false` by default appium:ignoreHiddenApiPolicyError | Being set to `true` ignores a failure while changing hidden API access policies. Could be useful on some devices, where access to these policies has been locked by its vendor. `false` by default. +pium:hideKeyboard | Being set to `true` hides the on-screen keyboard while the session is running. Use it instead of the legacy `appium:unicodeKeyboard` one (which will be dropped in the future). This effect is achieved by assigning a custom "artificial" [input method](https://developer.android.com/develop/ui/views/touch-and-input/creating-input-method). Only use this feature for special/exploratory cases as it violates the way your application under test is normally interacted with by a human. Setting this capability explicitly to `false` enforces `adb shell ime reset` call on session startup, which resets the currently selected/enabled IMEs to the default ones as if the device is initially booted with the current locale. `undefined` by default. appium:mockLocationApp | Sets the package identifier of the app, which is used as a system mock location provider since Appium 1.18.0+. This capability has no effect on emulators. If the value is set to `null` or an empty string, then Appium will skip the mocked location provider setup procedure. Defaults to Appium Setting package identifier (`io.appium.settings`). appium:logcatFormat | The log print format, where `format` is one of: `brief` `process` `tag` `thread` `raw` `time` `threadtime` `long`. `threadtime` is the default value. appium:logcatFilterSpecs | Series of `tag[:priority]` where `tag` is a log component tag (or * for all) and priority is: `V Verbose`, `D Debug`, `I Info`, `W Warn`, `E Error`, `F Fatal`, `S Silent (supress all output)`. '*' means '*:d' and `tag` by itself means `tag:v`. If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS. If no filterspec is found, filter defaults to '*:I'. diff --git a/lib/driver.js b/lib/driver.js index 31af2497..17b04a2a 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -141,6 +141,8 @@ const SUPPORTED_EXTENSIONS = [APK_EXT, AAB_EXT]; * >} */ class EspressoDriver extends AndroidDriver { + /** @type {string|null} */ + _originalIme; /** @type {import('./types').EspressoDriverOpts} */ opts; @@ -165,6 +167,7 @@ class EspressoDriver extends AndroidDriver { ]; this.desiredCapConstraints = ESPRESSO_CONSTRAINTS; this.jwpProxyAvoid = NO_PROXY; + this._originalIme = null; this.settings = new DeviceSettings({}, this.onSettingsUpdate.bind(this)); @@ -379,7 +382,9 @@ class EspressoDriver extends AndroidDriver { } // start an avd, set the language/locale, pick an emulator, etc... - // TODO with multiple devices we'll need to parameterize this + if (this.opts.hideKeyboard) { + this._originalIme = await this.adb.defaultIME(); + } await helpers.initDevice(this.adb, this.opts); // https://github.com/appium/appium-espresso-driver/issues/72 @@ -611,6 +616,13 @@ class EspressoDriver extends AndroidDriver { this.log.warn(`Unable to reset animation: ${err.message}`); } } + if (this._originalIme) { + try { + await this.adb.setIME(this._originalIme); + } catch (e) { + this.log.warn(`Cannot restore the original IME: ${e.message}`); + } + } if (!this.isChromeSession && this.opts.appPackage && !this.opts.dontStopAppOnReset) { await this.adb.forceStop(this.opts.appPackage); } diff --git a/package.json b/package.json index 93d42dfa..1171934e 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ ], "dependencies": { "appium-adb": "^11.0.1", - "appium-android-driver": "^7.1.3", + "appium-android-driver": "^7.2.1", "asyncbox": "^2.3.1", "bluebird": "^3.5.0", "lodash": "^4.17.11",