@@ -2,7 +2,7 @@ import { Point } from "./point";
22import { Direction } from "./direction" ;
33import { INsCapabilities } from "./interfaces/ns-capabilities" ;
44import { AutomationName } from "./automation-name" ;
5- import { calculateOffset } from "./utils" ;
5+ import { calculateOffset , adbShellCommand } from "./utils" ;
66import { AndroidKeyEvent } from "mobile-devices-controller" ;
77
88export class UIElement {
@@ -382,12 +382,21 @@ export class UIElement {
382382 * Send keys to field or other UI component
383383 * @param text
384384 * @param shouldClearText, default value is true
385+ * @param useAdb, default value is false. Usable for Android ONLY !
385386 */
386- public async sendKeys ( text : string , shouldClearText : boolean = true ) {
387- if ( shouldClearText ) {
388- await this . clearText ( ) ;
387+ public async sendKeys ( text : string , shouldClearText : boolean = true , useAdb : boolean = false ) {
388+ if ( useAdb && this . _args . isAndroid ) {
389+ if ( shouldClearText ) {
390+ await this . adbDeleteText ( ) ;
391+ }
392+ await this . click ( ) ;
393+ await adbShellCommand ( this . _driver , "input" , [ "text" , text ] ) ;
394+ } else {
395+ if ( shouldClearText ) {
396+ await this . clearText ( ) ;
397+ }
398+ await this . _element . sendKeys ( text ) ;
389399 }
390- await this . _element . sendKeys ( text ) ;
391400 }
392401
393402 /**
@@ -407,17 +416,29 @@ export class UIElement {
407416 * @param key code
408417 */
409418 public async pressKeycode ( keyCode : number ) {
410- await this . _driver . pressKeycode ( keyCode ) ;
419+ await this . _driver . pressKeyCode ( keyCode ) ;
411420 }
412421
413422 /**
414- * Clears text form ui element
423+ * Clears text from ui element
415424 */
416425 public async clearText ( ) {
417426 await this . click ( ) ;
418427 await this . _element . clear ( ) ;
419428 }
420429
430+ /**
431+ * Clears text from ui element with ADB. Android ONLY !
432+ * @param charactersCount Characters count to delete. (Optional - default value 10)
433+ */
434+ public async adbDeleteText ( charactersCount : number = 10 ) {
435+ await this . click ( ) ;
436+ for ( let index = 0 ; index < charactersCount ; index ++ ) {
437+ // Keyevent 67 Delete (backspace)
438+ await adbShellCommand ( this . _driver , "input" , [ "keyevent" , AndroidKeyEvent . KEYCODE_DEL ] ) ;
439+ }
440+ }
441+
421442 public async log ( ) {
422443 const el = await this . element ( ) ;
423444 console . dir ( el ) ;
0 commit comments