cabbie-sync
Version:
A synchronous webdriver client
338 lines (226 loc) • 9.93 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _mouseButtons = require('./enums/mouse-buttons');
var _mouseButtons2 = _interopRequireDefault(_mouseButtons);
var _httpMethod = require('./flow-types/http-method');
var _debug = require('./debug');
var _debug2 = _interopRequireDefault(_debug);
var _driver = require('./driver');
var _driver2 = _interopRequireDefault(_driver);
var _element = require('./element');
var _element2 = _interopRequireDefault(_element);
var _util = require('util');
var _addDebugging = require('./add-debugging');
var _addDebugging2 = _interopRequireDefault(_addDebugging);
var _flowRuntime = require('flow-runtime');
var _flowRuntime2 = _interopRequireDefault(_flowRuntime);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Element = _flowRuntime2.default.tdz(function () {
return _element2.default;
});
/*
* Mouse commands relative to a DOM-element
*/
/**
*
* This file is generated automatically, run npm run build to re-generate.
**/
var Driver = _flowRuntime2.default.tdz(function () {
return _driver2.default;
});
var Debug = _flowRuntime2.default.tdz(function () {
return _debug2.default;
});
var HttpMethod = _flowRuntime2.default.tdz(function () {
return _httpMethod.HttpMethod;
});
var MouseButton = _flowRuntime2.default.tdz(function () {
return _mouseButtons.MouseButton;
});
var Mouse = function () {
/*
* @private
*/
function Mouse(driver /*: Driver*/, parent /*: Element*/) {
(0, _classCallCheck3.default)(this, Mouse);
var _driverType = _flowRuntime2.default.ref(Driver);
var _parentType = _flowRuntime2.default.ref(Element);
_flowRuntime2.default.param('driver', _driverType).assert(driver);
_flowRuntime2.default.param('parent', _parentType).assert(parent);
this.driver = driver;
this.debug = driver.debug;
this._parent = parent;
}
/*
* @private
*/
/*
* @private
*/
(0, _createClass3.default)(Mouse, [{
key: 'requestJSON',
value: function requestJSON(method /*: HttpMethod*/, path /*: string*/, body /*:: ?: Object*/) /*: any*/ {
var _methodType = _flowRuntime2.default.ref(HttpMethod);
var _pathType = _flowRuntime2.default.string();
var _bodyType = _flowRuntime2.default.object();
var _returnType = _flowRuntime2.default.return(_flowRuntime2.default.any());
_flowRuntime2.default.param('method', _methodType).assert(method);
_flowRuntime2.default.param('path', _pathType).assert(path);
_flowRuntime2.default.param('body', _bodyType, true).assert(body);
return _returnType.assert(this._parent.requestJSON(method, path, body));
}
/*
* Click any mouse button at the center of the element
*/
}, {
key: 'click',
value: function click() /*: void*/ {
var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT;
var _buttonType = _flowRuntime2.default.ref(MouseButton);
var _returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('button', _buttonType).assert(button);
if (button !== _mouseButtons2.default.LEFT) {
this.moveToCenter();
this.driver.activeWindow.mouse.click(button);
} else {
this.requestJSON('POST', '/click');
}
}
/*
* Click any mouse button at a specified offset of the element
*/
}, {
key: 'clickAt',
value: function clickAt(xOffset /*: number*/, yOffset /*: number*/) /*: void*/ {
var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT;
var _xOffsetType = _flowRuntime2.default.number();
var _yOffsetType = _flowRuntime2.default.number();
var _buttonType2 = _flowRuntime2.default.ref(MouseButton);
var _returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType2).assert(button);
this.moveTo(xOffset, yOffset);
this.driver.activeWindow.mouse.click(button);
}
/*
* Move the mouse by an offset of the element
*/
}, {
key: 'moveTo',
value: function moveTo(xOffset /*: number*/, yOffset /*: number*/) /*: void*/ {
var _xOffsetType2 = _flowRuntime2.default.number();
var _yOffsetType2 = _flowRuntime2.default.number();
var _returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType2).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType2).assert(yOffset);
this.driver.activeWindow.mouse._moveTo(this._parent.elementID, xOffset, yOffset);
}
/*
* Move the mouse to the center of the element
*/
}, {
key: 'moveToCenter',
value: function moveToCenter() /*: void*/ {
var _returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.void());
this.driver.activeWindow.mouse._moveTo(this._parent.elementID, undefined, undefined);
}
/*
* Double-clicks the element at the center of the element
*/
}, {
key: 'doubleClick',
value: function doubleClick() /*: void*/ {
var _returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.void());
this.moveToCenter();
this.driver.activeWindow.mouse.doubleClick();
}
/*
* Double-clicks the element at a specified offset of the element
*/
}, {
key: 'doubleClickAt',
value: function doubleClickAt(xOffset /*: number*/, yOffset /*: number*/) /*: void*/ {
var _xOffsetType3 = _flowRuntime2.default.number();
var _yOffsetType3 = _flowRuntime2.default.number();
var _returnType7 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType3).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType3).assert(yOffset);
this.moveTo(xOffset, yOffset);
this.driver.activeWindow.mouse.doubleClick();
}
/*
* Click and hold any mouse button at the center of the element
*/
}, {
key: 'buttonDown',
value: function buttonDown() /*: void*/ {
var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT;
var _buttonType3 = _flowRuntime2.default.ref(MouseButton);
var _returnType8 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('button', _buttonType3).assert(button);
this.moveToCenter();
this.driver.activeWindow.mouse.buttonDown(button);
}
/*
* Click and hold any mouse button at a specified offset of the element
*/
}, {
key: 'buttonDownAt',
value: function buttonDownAt(xOffset /*: number*/, yOffset /*: number*/) /*: void*/ {
var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT;
var _xOffsetType4 = _flowRuntime2.default.number();
var _yOffsetType4 = _flowRuntime2.default.number();
var _buttonType4 = _flowRuntime2.default.ref(MouseButton);
var _returnType9 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType4).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType4).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType4).assert(button);
this.moveTo(xOffset, yOffset);
this.driver.activeWindow.mouse.buttonDown(button);
}
/*
* Releases a mouse button at the center of the element
*/
}, {
key: 'buttonUp',
value: function buttonUp() /*: void*/ {
var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT;
var _buttonType5 = _flowRuntime2.default.ref(MouseButton);
var _returnType10 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('button', _buttonType5).assert(button);
this.moveToCenter();
this.driver.activeWindow.mouse.buttonUp(button);
}
/*
* Releases a mouse button at a specified offset of the element
*/
}, {
key: 'buttonUpAt',
value: function buttonUpAt(xOffset /*: number*/, yOffset /*: number*/) /*: void*/ {
var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT;
var _xOffsetType5 = _flowRuntime2.default.number();
var _yOffsetType5 = _flowRuntime2.default.number();
var _buttonType6 = _flowRuntime2.default.ref(MouseButton);
var _returnType11 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType5).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType5).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType6).assert(button);
this.moveTo(xOffset, yOffset);
this.driver.activeWindow.mouse.buttonUp(button);
}
}]);
return Mouse;
}();
(0, _addDebugging2.default)(Mouse, {
inspect: function inspect(obj, depth, options) {
return obj._parent[_util.inspect.custom || 'inspect'](depth, options) + '.mouse';
}
});
exports.default = Mouse;