Skip to content
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
5 changes: 5 additions & 0 deletions lib/ui-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ export declare class UIElement {
* Easy to use in order to chain and search for nested elemetns
*/
driver(): any;
/**
* Swipe element left/right
* @param direction
*/
swipe(direction: Direction): Promise<void>;
}
37 changes: 37 additions & 0 deletions lib/ui-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,41 @@ export class UIElement {
public driver() {
return this._element.browser;
}

/**
* Swipe element left/right
* @param direction
*/
public async swipe(direction: Direction){
const rectangle = await this.getRectangle();
const centerX = rectangle.x + rectangle.width / 2;
const centerY = rectangle.y + rectangle.height / 2;
let swipeX;
if(direction == Direction.right){
const windowSize = await this._driver.getWindowSize();
swipeX = windowSize.width - 10;
} else if (direction == Direction.left){
swipeX = 10;
} else {
console.log("Provided direction must be left or right !");
}

if (this._args.isAndroid) {
const action = new this._wd.TouchAction(this._driver);
action.press({ x: centerX, y: centerY })
.wait(100)
.moveTo({ x: swipeX, y: centerY })
.release();
await action.perform();
}
else {
await this._driver.execute('mobile: dragFromToForDuration', {
duration: 2.0,
fromX: centerX,
fromY: centerY,
toX: swipeX,
toY: centerY
});
}
}
}