Skip to content

Commit 7e5608a

Browse files
author
Zdravko
authored
chore: add clickPoint functionality (#87)
that clicks over the screen by provided coordinates. Add wait and search for element that might not exist.
1 parent 417c7eb commit 7e5608a

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

lib/appium-driver.d.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export declare class AppiumDriver {
2424
private _logPath;
2525
private _storageByDeviceName;
2626
private _storageByPlatform;
27-
private constructor();
27+
private constructor(_driver, _wd, _webio, _driverConfig, _args);
2828
readonly imageHelper: ImageHelper;
2929
defaultWaitTime: number;
3030
readonly capabilities: any;
@@ -120,6 +120,12 @@ export declare class AppiumDriver {
120120
* @param xOffset
121121
*/
122122
swipe(y: number, x: number, yOffset: number, inertia?: number, xOffset?: number): Promise<void>;
123+
/**
124+
* Click a point by providing coordinates
125+
* @param x
126+
* @param y
127+
*/
128+
clickPoint(xCoordinate: number, yCoordinate: number): Promise<void>;
123129
source(): Promise<any>;
124130
sessionId(): Promise<any>;
125131
compareElement(element: UIElement, imageName: string): Promise<boolean>;
@@ -138,4 +144,22 @@ export declare class AppiumDriver {
138144
private convertArrayToUIElements(array, searchM, args);
139145
private static configureLogging(driver, verbose);
140146
private getExpectedImagePath(imageName);
147+
/**
148+
* Wait specific amount of time before continue execution
149+
* @param miliseconds
150+
*/
151+
wait(miliseconds: number): Promise<void>;
152+
/**
153+
* Search for element by given xPath but does not throw error if can not find it. Instead returns 'undefined'.
154+
* @param xPath
155+
* @param waitForElement
156+
*/
157+
findElementByXPathIfExists(xPath: string, waitForElement?: number): Promise<any>;
158+
/**
159+
* Search for element by given text but does not throw error if can not find it. Instead returns 'undefined'.
160+
* @param text
161+
* @param match
162+
* @param waitForElement
163+
*/
164+
findElementByTextIfExists(text: string, match?: SearchOptions, waitForElement?: number): Promise<any>;
141165
}

lib/appium-driver.ts

+47
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@ export class AppiumDriver {
265265
await this._driver.sleep(150);
266266
}
267267

268+
/**
269+
* Click a point by providing coordinates
270+
* @param x
271+
* @param y
272+
*/
273+
public async clickPoint(xCoordinate: number, yCoordinate: number) {
274+
let action = new this._wd.TouchAction(this._driver);
275+
action
276+
.tap({ x: xCoordinate, y: yCoordinate });
277+
await action.perform();
278+
await this._driver.sleep(150);
279+
}
280+
268281
public async source() {
269282
return await this._webio.source();
270283
}
@@ -533,4 +546,38 @@ export class AppiumDriver {
533546

534547
return pathExpectedImage;
535548
}
549+
550+
/**
551+
* Wait specific amount of time before continue execution
552+
* @param miliseconds
553+
*/
554+
public async wait(miliseconds: number) {
555+
await this._driver.sleep(miliseconds);
556+
}
557+
558+
/**
559+
* Search for element by given xPath but does not throw error if can not find it. Instead returns 'undefined'.
560+
* @param xPath
561+
* @param waitForElement
562+
*/
563+
public async findElementByXPathIfExists(xPath: string, waitForElement: number = this.defaultWaitTime) {
564+
const element = await this._driver.elementByXPathIfExists(xPath, waitForElement);
565+
if (element) {
566+
const searchMethod = "elementByXPathIfExists";
567+
return await new UIElement(element, this._driver, this._wd, this._webio, this._args, searchMethod, xPath);
568+
} else {
569+
return undefined;
570+
}
571+
}
572+
573+
/**
574+
* Search for element by given text but does not throw error if can not find it. Instead returns 'undefined'.
575+
* @param text
576+
* @param match
577+
* @param waitForElement
578+
*/
579+
public async findElementByTextIfExists(text: string, match: SearchOptions = SearchOptions.exact, waitForElement: number = this.defaultWaitTime) {
580+
const shouldMatch = match === SearchOptions.exact ? true : false;
581+
return await this.findElementByXPathIfExists(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
582+
}
536583
}

lib/ui-element.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export declare class UIElement {
105105
* Click and hold over an element
106106
*/
107107
hold(): Promise<void>;
108+
/**
109+
* Send keys to field or other UI component
110+
* @param text
111+
*/
112+
sendKeys(text: string): Promise<void>;
108113
log(): Promise<void>;
109114
refetch(): Promise<any>;
110115
}

lib/ui-element.ts

+8
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ export class UIElement {
243243
await this._driver.sleep(150);
244244
}
245245

246+
/**
247+
* Send keys to field or other UI component
248+
* @param text
249+
*/
250+
public async sendKeys(text: string) {
251+
await this._element.sendKeys(text);
252+
}
253+
246254
public async log() {
247255
console.dir(await this.element());
248256
}

0 commit comments

Comments
 (0)