Skip to content

Commit 45a8ff6

Browse files
feat: extend interaction with text (#208)
* feat: extend interaction with text
1 parent df9e6ed commit 45a8ff6

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

Diff for: lib/appium-driver.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ export declare class AppiumDriver {
198198
* @param time in minutes
199199
*/
200200
backgroundApp(minutes: number): Promise<void>;
201+
/**
202+
* Hides device keyboard
203+
*/
204+
hideDeviceKeyboard(): Promise<void>;
205+
isKeyboardShown(): Promise<any>;
201206
resetApp(): Promise<void>;
202207
init(): Promise<void>;
203208
quit(): Promise<void>;

Diff for: lib/appium-driver.ts

+11
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,17 @@ export class AppiumDriver {
734734
await this._driver.backgroundApp(minutes);
735735
}
736736

737+
/**
738+
* Hides device keyboard
739+
*/
740+
public async hideDeviceKeyboard() {
741+
await this._driver.hideDeviceKeyboard();
742+
}
743+
744+
public async isKeyboardShown() {
745+
return await this._driver.isKeyboardShown();
746+
}
747+
737748
public async resetApp() {
738749
await this._driver.resetApp();
739750
}

Diff for: lib/ui-element.d.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export declare class UIElement {
1717
*/
1818
click(): Promise<any>;
1919
tapCenter(): Promise<void>;
20+
tapAtTheEnd(): Promise<void>;
2021
/**
2122
* Tap on element
2223
*/
@@ -107,7 +108,7 @@ export declare class UIElement {
107108
* @param yOffset
108109
* @param xOffset
109110
*/
110-
scrollTo(direction: Direction, elementToSearch: any, yOffset?: number, xOffset?: number): Promise<UIElement>;
111+
scrollTo(direction: Direction, elementToSearch: () => Promise<UIElement>, yOffset?: number, xOffset?: number, retries?: number): Promise<UIElement>;
111112
/**
112113
* Scroll with offset from element with minimum inertia
113114
* @param direction
@@ -123,8 +124,24 @@ export declare class UIElement {
123124
/**
124125
* Send keys to field or other UI component
125126
* @param text
127+
* @param shouldClearText, default value is true
126128
*/
127-
sendKeys(text: string): Promise<void>;
129+
sendKeys(text: string, shouldClearText?: boolean): Promise<void>;
130+
/**
131+
* Type text to field or other UI component
132+
* @param text
133+
* @param shouldClearText, default value is true
134+
*/
135+
type(text: string, shouldClearText?: boolean): Promise<void>;
136+
/**
137+
* Send key code to device
138+
* @param key code
139+
*/
140+
pressKeycode(keyCode: number): Promise<void>;
141+
/**
142+
* Clears text form ui element
143+
*/
144+
clearText(): Promise<void>;
128145
log(): Promise<void>;
129146
refetch(): Promise<any>;
130147
/**

Diff for: lib/ui-element.ts

+43-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Point } from "./point";
22
import { Direction } from "./direction";
33
import { INsCapabilities } from "./interfaces/ns-capabilities";
4-
import { IRectangle } from "./interfaces/rectangle";
54
import { AutomationName } from "./automation-name";
65
import { calculateOffset } from "./utils";
6+
import { AndroidKeyEvent } from "mobile-devices-controller";
77

88
export class UIElement {
99
private static readonly DEFAULT_REFETCH_TIME = 1000;
@@ -33,6 +33,15 @@ export class UIElement {
3333
await this._driver.sleep(150);
3434
}
3535

36+
public async tapAtTheEnd() {
37+
let action = new this._wd.TouchAction(this._driver);
38+
const rect = await this.getActualRectangle();
39+
action
40+
.tap({ x: (rect.x + rect.width) - 1, y: rect.y + rect.height / 2 });
41+
await action.perform();
42+
await this._driver.sleep(150);
43+
}
44+
3645
/**
3746
* Tap on element
3847
*/
@@ -364,11 +373,43 @@ export class UIElement {
364373
/**
365374
* Send keys to field or other UI component
366375
* @param text
376+
* @param shouldClearText, default value is true
367377
*/
368-
public async sendKeys(text: string) {
378+
public async sendKeys(text: string, shouldClearText: boolean = true) {
379+
if (shouldClearText) {
380+
await this.clearText();
381+
}
369382
await this._element.sendKeys(text);
370383
}
371384

385+
/**
386+
* Type text to field or other UI component
387+
* @param text
388+
* @param shouldClearText, default value is true
389+
*/
390+
public async type(text: string, shouldClearText: boolean = true) {
391+
if (shouldClearText) {
392+
await this.clearText();
393+
}
394+
await this._element.type(text);
395+
}
396+
397+
/**
398+
* Send key code to device
399+
* @param key code
400+
*/
401+
public async pressKeycode(keyCode: number) {
402+
await this._driver.pressKeycode(keyCode);
403+
}
404+
405+
/**
406+
* Clears text form ui element
407+
*/
408+
public async clearText() {
409+
await this.click();
410+
await this._element.clear();
411+
}
412+
372413
public async log() {
373414
console.dir(await this.element());
374415
}

0 commit comments

Comments
 (0)