UNPKG

appium-android-driver

Version:

Android UiAutomator and Chrome support for Appium

133 lines 4.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.hideKeyboard = hideKeyboard; exports.isKeyboardShown = isKeyboardShown; exports.keys = keys; exports.doSendKeys = doSendKeys; exports.keyevent = keyevent; exports.pressKeyCode = pressKeyCode; exports.longPressKeyCode = longPressKeyCode; exports.mobilePerformEditorAction = mobilePerformEditorAction; exports.initUnicodeKeyboard = initUnicodeKeyboard; exports.hideKeyboardCompletely = hideKeyboardCompletely; /* eslint-disable @typescript-eslint/no-unused-vars */ const lodash_1 = __importDefault(require("lodash")); const driver_1 = require("appium/driver"); const io_appium_settings_1 = require("io.appium.settings"); /** * Hides the on-screen keyboard. * * @returns Promise that resolves to `true` if the keyboard was hidden, `false` otherwise. */ async function hideKeyboard() { return await this.adb.hideKeyboard(); } /** * Checks if the on-screen keyboard is currently shown. * * @returns Promise that resolves to `true` if the keyboard is shown, `false` otherwise. */ async function isKeyboardShown() { const { isKeyboardShown } = await this.adb.isSoftKeyboardPresent(); return isKeyboardShown; } /** * Sends keys to the active element. * * @param keys The keys to send, either as a string or an array of strings (which will be joined). * @returns Promise that resolves when the keys are sent. */ async function keys(keys) { // Protocol sends an array; rethink approach const keysStr = lodash_1.default.isArray(keys) ? keys.join('') : keys; await this.doSendKeys({ text: keysStr, replace: false, }); } /** * Sends keys to the active element. * * @param params The parameters for sending keys. * @returns Promise that resolves when the keys are sent. * @throws {errors.NotImplementedError} This method is not implemented. */ async function doSendKeys(params) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Sends a key event to the device. * * @deprecated Use {@link pressKeyCode} instead. * @param keycode The key code to press. * @param metastate Optional meta state flags. * @returns Promise that resolves when the key event is sent. */ async function keyevent(keycode, metastate) { // TODO deprecate keyevent; currently wd only implements keyevent this.log.warn('keyevent will be deprecated use pressKeyCode'); return await this.pressKeyCode(keycode, metastate); } /** * Presses a key code on the device. * * @param keycode The key code to press. * @param metastate Optional meta state flags. * @returns Promise that resolves when the key code is pressed. * @throws {errors.NotImplementedError} This method is not implemented. */ async function pressKeyCode(keycode, metastate) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Long presses a key code on the device. * * @param keycode The key code to long press. * @param metastate Optional meta state flags. * @returns Promise that resolves when the key code is long pressed. * @throws {errors.NotImplementedError} This method is not implemented. */ async function longPressKeyCode(keycode, metastate) { throw new driver_1.errors.NotImplementedError('Not implemented'); } /** * Performs an editor action on the active input field. * * @param action The editor action to perform (e.g., 'done', 'go', 'next'). * @returns Promise that resolves when the editor action is performed. */ async function mobilePerformEditorAction(action) { await this.settingsApp.performEditorAction(action); } // #region Internal Helpers /** * Initializes Unicode keyboard support. * * @deprecated * @returns Promise that resolves to the default IME identifier that was active before. */ async function initUnicodeKeyboard() { this.log.debug('Enabling Unicode keyboard support'); // get the default IME so we can return back to it later if we want const defaultIME = await this.adb.defaultIME(); this.log.debug(`Unsetting previous IME ${defaultIME}`); this.log.debug(`Setting IME to '${io_appium_settings_1.UNICODE_IME}'`); await this.adb.enableIME(io_appium_settings_1.UNICODE_IME); await this.adb.setIME(io_appium_settings_1.UNICODE_IME); return defaultIME; } /** * Hides the on-screen keyboard completely by setting IME to empty. * * @returns Promise that resolves when the keyboard is hidden. */ async function hideKeyboardCompletely() { this.log.debug(`Hiding the on-screen keyboard by setting IME to '${io_appium_settings_1.EMPTY_IME}'`); await this.adb.enableIME(io_appium_settings_1.EMPTY_IME); await this.adb.setIME(io_appium_settings_1.EMPTY_IME); } // #endregion //# sourceMappingURL=keyboard.js.map