cabbie-sync
Version:
A synchronous webdriver client
280 lines (182 loc) • 9.06 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _mouseButtons = require('./enums/mouse-buttons');
var _mouseButtons2 = _interopRequireDefault(_mouseButtons);
var _addDebugging = require('./add-debugging');
var _addDebugging2 = _interopRequireDefault(_addDebugging);
var _baseClass = require('./base-class');
var _baseClass2 = _interopRequireDefault(_baseClass);
var _mouse = require('./mouse');
var _mouse2 = _interopRequireDefault(_mouse);
var _flowRuntime = require('flow-runtime');
var _flowRuntime2 = _interopRequireDefault(_flowRuntime);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
*
* This file is generated automatically, run npm run build to re-generate.
**/
var MouseButton = _flowRuntime2.default.tdz(function () {
return _mouseButtons.MouseButton;
});
/*
* Global mouse object handling global mouse commands
*/
var GlobalMouse = function (_BaseClass) {
(0, _inherits3.default)(GlobalMouse, _BaseClass);
function GlobalMouse() {
(0, _classCallCheck3.default)(this, GlobalMouse);
return (0, _possibleConstructorReturn3.default)(this, (GlobalMouse.__proto__ || (0, _getPrototypeOf2.default)(GlobalMouse)).apply(this, arguments));
}
(0, _createClass3.default)(GlobalMouse, [{
key: '_moveTo',
/*
* Move the mouse by an offset of the specified element. If no element is specified,
* the move is relative to the current mouse cursor. If an element is provided but
* no offset, the mouse will be moved to the center of the element. If the element
* is not visible, it will be scrolled into view.
*/
value: function _moveTo(elementId /*:: ?: string*/, xOffset /*:: ?: number*/, yOffset /*:: ?: number*/) /*: void*/ {
var _elementIdType = _flowRuntime2.default.string();
var _xOffsetType = _flowRuntime2.default.number();
var _yOffsetType = _flowRuntime2.default.number();
var _returnType = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('elementId', _elementIdType, true).assert(elementId);
_flowRuntime2.default.param('xOffset', _xOffsetType, true).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType, true).assert(yOffset);
var _paramsType = _flowRuntime2.default.object(),
params = _paramsType.assert({});
if (elementId !== undefined) {
params.element = elementId;
}
if (xOffset !== undefined || yOffset !== undefined) {
params.xoffset = xOffset;
params.yoffset = yOffset;
}
this.requestJSON('POST', '/moveto', params);
}
/*
* Move the mouse by an offset relative to the current mouse cursor position
*/
}, {
key: 'moveTo',
value: function moveTo(xOffset /*: number*/, yOffset /*: number*/) /*: void*/ {
var _xOffsetType2 = _flowRuntime2.default.number();
var _yOffsetType2 = _flowRuntime2.default.number();
var _returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType2).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType2).assert(yOffset);
this._moveTo(undefined, xOffset, yOffset);
}
/*
* Click any mouse button at the current location of the mouse cursor
*/
}, {
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 _returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('button', _buttonType).assert(button);
this.requestJSON('POST', '/click', { button: button });
}
/*
* Click any mouse button at an offset relative to the current location of the mouse cursor
*/
}, {
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 _xOffsetType3 = _flowRuntime2.default.number();
var _yOffsetType3 = _flowRuntime2.default.number();
var _buttonType2 = _flowRuntime2.default.ref(MouseButton);
var _returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('xOffset', _xOffsetType3).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType3).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType2).assert(button);
this.moveTo(xOffset, yOffset);
this.click(button);
}
/*
* Double-clicks at the current location of the mouse cursor
*/
}, {
key: 'doubleClick',
value: function doubleClick() /*: void*/ {
var _returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.void());
this.requestJSON('POST', '/doubleclick');
}
/*
* Click and hold the any mouse button at the current location of the mouse cursor
*/
}, {
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 _returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('button', _buttonType3).assert(button);
this.requestJSON('POST', '/buttondown', { button: button });
}
/*
* Click and hold the any mouse button relative to the current location of the mouse cursor
*/
}, {
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 _returnType7 = _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.buttonDown(button);
}
/*
* Releases the mouse button previously held at the current location of the mouse cursor
*/
}, {
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 _returnType8 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('button', _buttonType5).assert(button);
this.requestJSON('POST', '/buttonup', { button: button });
}
/*
* Releases the mouse button previously held at the current location of the mouse cursor
*/
}, {
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 _returnType9 = _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.buttonUp(button);
}
}]);
return GlobalMouse;
}(_baseClass2.default);
(0, _addDebugging2.default)(GlobalMouse);
exports.default = GlobalMouse;