Skip to content

chore: add clickPoint functionality #87

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
Feb 16, 2018
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
26 changes: 25 additions & 1 deletion lib/appium-driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export declare class AppiumDriver {
private _logPath;
private _storageByDeviceName;
private _storageByPlatform;
private constructor();
private constructor(_driver, _wd, _webio, _driverConfig, _args);
readonly imageHelper: ImageHelper;
defaultWaitTime: number;
readonly capabilities: any;
Expand Down Expand Up @@ -120,6 +120,12 @@ export declare class AppiumDriver {
* @param xOffset
*/
swipe(y: number, x: number, yOffset: number, inertia?: number, xOffset?: number): Promise<void>;
/**
* Click a point by providing coordinates
* @param x
* @param y
*/
clickPoint(xCoordinate: number, yCoordinate: number): Promise<void>;
source(): Promise<any>;
sessionId(): Promise<any>;
compareElement(element: UIElement, imageName: string): Promise<boolean>;
Expand All @@ -138,4 +144,22 @@ export declare class AppiumDriver {
private convertArrayToUIElements(array, searchM, args);
private static configureLogging(driver, verbose);
private getExpectedImagePath(imageName);
/**
* Wait specific amount of time before continue execution
* @param miliseconds
*/
wait(miliseconds: number): Promise<void>;
/**
* Search for element by given xPath but does not throw error if can not find it. Instead returns 'undefined'.
* @param xPath
* @param waitForElement
*/
findElementByXPathIfExists(xPath: string, waitForElement?: number): Promise<any>;
/**
* Search for element by given text but does not throw error if can not find it. Instead returns 'undefined'.
* @param text
* @param match
* @param waitForElement
*/
findElementByTextIfExists(text: string, match?: SearchOptions, waitForElement?: number): Promise<any>;
}
47 changes: 47 additions & 0 deletions lib/appium-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ export class AppiumDriver {
await this._driver.sleep(150);
}

/**
* Click a point by providing coordinates
* @param x
* @param y
*/
public async clickPoint(xCoordinate: number, yCoordinate: number) {
let action = new this._wd.TouchAction(this._driver);
action
.tap({ x: xCoordinate, y: yCoordinate });
await action.perform();
await this._driver.sleep(150);
}

public async source() {
return await this._webio.source();
}
Expand Down Expand Up @@ -533,4 +546,38 @@ export class AppiumDriver {

return pathExpectedImage;
}

/**
* Wait specific amount of time before continue execution
* @param miliseconds
*/
public async wait(miliseconds: number) {
await this._driver.sleep(miliseconds);
}

/**
* Search for element by given xPath but does not throw error if can not find it. Instead returns 'undefined'.
* @param xPath
* @param waitForElement
*/
public async findElementByXPathIfExists(xPath: string, waitForElement: number = this.defaultWaitTime) {
const element = await this._driver.elementByXPathIfExists(xPath, waitForElement);
if (element) {
const searchMethod = "elementByXPathIfExists";
return await new UIElement(element, this._driver, this._wd, this._webio, this._args, searchMethod, xPath);
} else {
return undefined;
}
}

/**
* Search for element by given text but does not throw error if can not find it. Instead returns 'undefined'.
* @param text
* @param match
* @param waitForElement
*/
public async findElementByTextIfExists(text: string, match: SearchOptions = SearchOptions.exact, waitForElement: number = this.defaultWaitTime) {
const shouldMatch = match === SearchOptions.exact ? true : false;
return await this.findElementByXPathIfExists(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
}
}
5 changes: 5 additions & 0 deletions lib/ui-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export declare class UIElement {
* Click and hold over an element
*/
hold(): Promise<void>;
/**
* Send keys to field or other UI component
* @param text
*/
sendKeys(text: string): Promise<void>;
log(): Promise<void>;
refetch(): Promise<any>;
}
8 changes: 8 additions & 0 deletions lib/ui-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ export class UIElement {
await this._driver.sleep(150);
}

/**
* Send keys to field or other UI component
* @param text
*/
public async sendKeys(text: string) {
await this._element.sendKeys(text);
}

public async log() {
console.dir(await this.element());
}
Expand Down