From efc0932ae3fdad63a5bb1b26e788589b6ce75d06 Mon Sep 17 00:00:00 2001 From: Zdravko Branzov Date: Tue, 1 Oct 2019 17:14:15 +0300 Subject: [PATCH] fix: sendKeys command to input properly string with intervals. Add parameter for chars count to be deleted --- lib/appium-driver.d.ts | 3 +++ lib/appium-driver.ts | 3 +++ lib/ui-element.d.ts | 11 +++++++---- lib/ui-element.ts | 14 +++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index 22494f0..5746907 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -271,16 +271,19 @@ export declare class AppiumDriver { getScreenViewPort(): IRectangle; /** * Android ONLY! Input key event via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param keyEvent The event number */ adbKeyEvent(keyEvent: number | AndroidKeyEvent): Promise; /** * Android ONLY! Send text via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param text The string to send */ adbSendText(text: string): Promise; /** * Android ONLY! Execute shell command via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param command The command name * @param args Additional arguments */ diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 57ad452..513e075 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -1027,6 +1027,7 @@ export class AppiumDriver { /** * Android ONLY! Input key event via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param keyEvent The event number */ public async adbKeyEvent(keyEvent: number | AndroidKeyEvent) { @@ -1035,6 +1036,7 @@ export class AppiumDriver { /** * Android ONLY! Send text via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param text The string to send */ public async adbSendText(text: string) { @@ -1043,6 +1045,7 @@ export class AppiumDriver { /** * Android ONLY! Execute shell command via ADB. + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param command The command name * @param args Additional arguments */ diff --git a/lib/ui-element.d.ts b/lib/ui-element.d.ts index 6fe5cc5..2bb26d3 100644 --- a/lib/ui-element.d.ts +++ b/lib/ui-element.d.ts @@ -126,11 +126,13 @@ export declare class UIElement { hold(time?: number): Promise; /** * Send keys to field or other UI component - * @param text - * @param shouldClearText, default value is true - * @param useAdb, default value is false. Usable for Android ONLY ! + * @param text The string to input + * @param shouldClearText Clears existing input before send new one - default value is 'true' + * @param useAdb default value is false. Usable for Android ONLY ! + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. + * @param adbDeleteCharsCount default value is 10. Usable for Android ONLY when 'useAdb' and 'shouldClearText' are True! */ - sendKeys(text: string, shouldClearText?: boolean, useAdb?: boolean): Promise; + sendKeys(text: string, shouldClearText?: boolean, useAdb?: boolean, adbDeleteCharsCount?: number): Promise; /** * Type text to field or other UI component * @param text @@ -148,6 +150,7 @@ export declare class UIElement { clearText(): Promise; /** * Clears text from ui element with ADB. Android ONLY ! + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param charactersCount Characters count to delete. (Optional - default value 10) */ adbDeleteText(charactersCount?: number): Promise; diff --git a/lib/ui-element.ts b/lib/ui-element.ts index f6c09b0..3f89674 100644 --- a/lib/ui-element.ts +++ b/lib/ui-element.ts @@ -380,15 +380,18 @@ export class UIElement { /** * Send keys to field or other UI component - * @param text - * @param shouldClearText, default value is true - * @param useAdb, default value is false. Usable for Android ONLY ! + * @param text The string to input + * @param shouldClearText Clears existing input before send new one - default value is 'true' + * @param useAdb default value is false. Usable for Android ONLY ! + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. + * @param adbDeleteCharsCount default value is 10. Usable for Android ONLY when 'useAdb' and 'shouldClearText' are True! */ - public async sendKeys(text: string, shouldClearText: boolean = true, useAdb: boolean = false) { + public async sendKeys(text: string, shouldClearText: boolean = true, useAdb: boolean = false, adbDeleteCharsCount: number = 10) { if (useAdb && this._args.isAndroid) { if (shouldClearText) { - await this.adbDeleteText(); + await this.adbDeleteText(adbDeleteCharsCount); } + text = text.replace(" ","%s"); await this.click(); await adbShellCommand(this._driver, "input", ["text", text]); } else { @@ -429,6 +432,7 @@ export class UIElement { /** * Clears text from ui element with ADB. Android ONLY ! + * Must be combined with '--relaxed-security' appium flag. When not running in sauceLabs '--ignoreDeviceController' should be added too. * @param charactersCount Characters count to delete. (Optional - default value 10) */ public async adbDeleteText(charactersCount: number = 10) {