Skip to content

Commit

Permalink
feat: Add hideKeyboard capability (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Oct 30, 2023
1 parent 25a7cb6 commit 708f41c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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.
appium: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`). Termination of a mock location provider application resets the mocked location data.
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'.
Expand Down
14 changes: 13 additions & 1 deletion lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class AndroidUiautomator2Driver

_hasSystemPortInCaps: boolean | undefined;

_originalIme: string | null;

mjpegStream?: mjpeg.MJpegStream;

override caps: Uiautomator2DriverCaps;
Expand Down Expand Up @@ -210,6 +212,7 @@ class AndroidUiautomator2Driver
this.jwpProxyActive = false;
this.jwpProxyAvoid = NO_PROXY;
this.apkStrings = {}; // map of language -> strings obj
this._originalIme = null;

this.settings = new DeviceSettings(
{ignoreUnimportantViews: false, allowInvisibleElements: false},
Expand Down Expand Up @@ -485,7 +488,9 @@ class AndroidUiautomator2Driver
};

// 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);

// Prepare the device by forwarding the UiAutomator2 port
Expand Down Expand Up @@ -791,6 +796,13 @@ class AndroidUiautomator2Driver
this.log.info('Restoring window animation state');
await this.adb.setAnimationState(true);
}
if (this._originalIme) {
try {
await this.adb.setIME(this._originalIme);
} catch (e) {
this.log.warn(`Cannot restore the original IME: ${e.message}`);
}
}
await this.adb.stopLogcat();
try {
await this.releaseSystemPort();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"appium-adb": "^11.0.1",
"appium-android-driver": "^7.1.3",
"appium-android-driver": "^7.2.1",
"appium-chromedriver": "^5.6.5",
"appium-uiautomator2-server": "^5.12.2",
"asyncbox": "^2.3.1",
Expand Down

0 comments on commit 708f41c

Please sign in to comment.