Skip to content

fix: sendKeys command to input properly string with intervals. #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/appium-driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
/**
* 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<void>;
/**
* 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
*/
Expand Down
3 changes: 3 additions & 0 deletions lib/appium-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
*/
Expand Down
11 changes: 7 additions & 4 deletions lib/ui-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ export declare class UIElement {
hold(time?: number): Promise<void>;
/**
* 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<void>;
sendKeys(text: string, shouldClearText?: boolean, useAdb?: boolean, adbDeleteCharsCount?: number): Promise<void>;
/**
* Type text to field or other UI component
* @param text
Expand All @@ -148,6 +150,7 @@ export declare class UIElement {
clearText(): Promise<void>;
/**
* 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<void>;
Expand Down
14 changes: 9 additions & 5 deletions lib/ui-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down