cabbie-sync
Version:
A synchronous webdriver client
109 lines (96 loc) • 2.67 kB
Flow
/**
* @flow
* This file is generated automatically, run npm run build to re-generate.
**/
import type Debug from './debug';
import type Driver from './driver';
import type Element from './element';
import { inspect } from 'util';
import addDebugging from './add-debugging';
/*
* Touch commands relative to a DOM-element
*/
class Touch {
/*
* @private
*/
debug: Debug;
/*
* @private
*/
driver: Driver;
_parent: Element;
constructor(driver: Driver, parent: Element) {
this.debug = driver.debug;
this.driver = driver;
this._parent = parent;
}
/*
* Tap with the finger on the element
*/
tap(): void {
this.driver.activeWindow.touch._tap(this._parent.elementID);
}
/*
* Double tap with the finger on the element
*/
doubleTap(): void {
this.driver.activeWindow.touch._doubleTap(this._parent.elementID);
}
/*
* Long tap with the finger on the element
*/
longTap(): void {
this.driver.activeWindow.touch._longTap(this._parent.elementID);
}
/*
* Finger down on the screen at an offset relative to the element
*/
down(xOffset: number, yOffset: number): void {
const location = this._parent.getPosition();
this.driver.activeWindow.touch.down(location.x + xOffset, location.y + yOffset);
}
/*
* Finger down on the screen at the center of the element
*/
downAtCenter(): void {
const center = this._parent.getAbsoluteCenter();
this.driver.activeWindow.touch.down(center.x, center.y);
}
/*
* Finger up on the screen at an offset relative to the element
*/
up(xOffset: number, yOffset: number): void {
const location = this._parent.getPosition();
this.driver.activeWindow.touch.down(location.x + xOffset, location.y + yOffset);
}
/*
* Finger up on the screen at the center of the element
*/
upAtCenter(): void {
const center = this._parent.getAbsoluteCenter();
this.driver.activeWindow.touch.down(center.x, center.y);
}
/*
* Move finger to an offset relative to the element
*/
moveTo(xOffset: number, yOffset: number): void {
const location = this._parent.getPosition();
this.driver.activeWindow.touch.move(location.x + xOffset, location.y + yOffset);
}
/*
* Move finger to the center of the element
*/
moveToCenter(): void {
const center = this._parent.getAbsoluteCenter();
this.driver.activeWindow.touch.move(center.x, center.y);
}
//TODO: Element touch flick
//TODO: Element touch scroll
}
addDebugging(Touch, {
inspect(obj, depth, options) {
return obj._parent[inspect.custom || 'inspect'](depth, options) + '.touch';
}
});
export default Touch;