cabbie-async
Version:
An asynchronous webdriver client
401 lines (297 loc) • 14.6 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
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*/) /*: Promise<void>*/ {
var _elementIdType, _xOffsetType, _yOffsetType, _returnType, _paramsType, params;
return _regenerator2.default.async(function _moveTo$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_elementIdType = _flowRuntime2.default.string();
_xOffsetType = _flowRuntime2.default.number();
_yOffsetType = _flowRuntime2.default.number();
_returnType = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _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);
_paramsType = _flowRuntime2.default.object(), params = _paramsType.assert({});
if (elementId !== undefined) {
params.element = elementId;
}
if (xOffset !== undefined || yOffset !== undefined) {
params.xoffset = xOffset;
params.yoffset = yOffset;
}
_context.next = 12;
return _regenerator2.default.awrap(this.requestJSON('POST', '/moveto', params));
case 12:
case 'end':
return _context.stop();
}
}
}, null, this);
}
/*
* Move the mouse by an offset relative to the current mouse cursor position
*/
}, {
key: 'moveTo',
value: function moveTo(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ {
var _xOffsetType2, _yOffsetType2, _returnType2;
return _regenerator2.default.async(function moveTo$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_xOffsetType2 = _flowRuntime2.default.number();
_yOffsetType2 = _flowRuntime2.default.number();
_returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('xOffset', _xOffsetType2).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType2).assert(yOffset);
_context2.next = 7;
return _regenerator2.default.awrap(this._moveTo(undefined, xOffset, yOffset));
case 7:
case 'end':
return _context2.stop();
}
}
}, null, this);
}
/*
* Click any mouse button at the current location of the mouse cursor
*/
}, {
key: 'click',
value: function click() /*: Promise<void>*/ {
var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT;
var _buttonType, _returnType3;
return _regenerator2.default.async(function click$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_buttonType = _flowRuntime2.default.ref(MouseButton);
_returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('button', _buttonType).assert(button);
_context3.next = 5;
return _regenerator2.default.awrap(this.requestJSON('POST', '/click', { button: button }));
case 5:
case 'end':
return _context3.stop();
}
}
}, null, this);
}
/*
* 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*/) /*: Promise<void>*/ {
var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT;
var _xOffsetType3, _yOffsetType3, _buttonType2, _returnType4;
return _regenerator2.default.async(function clickAt$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_xOffsetType3 = _flowRuntime2.default.number();
_yOffsetType3 = _flowRuntime2.default.number();
_buttonType2 = _flowRuntime2.default.ref(MouseButton);
_returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('xOffset', _xOffsetType3).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType3).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType2).assert(button);
_context4.next = 9;
return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset));
case 9:
_context4.next = 11;
return _regenerator2.default.awrap(this.click(button));
case 11:
case 'end':
return _context4.stop();
}
}
}, null, this);
}
/*
* Double-clicks at the current location of the mouse cursor
*/
}, {
key: 'doubleClick',
value: function doubleClick() /*: Promise<void>*/ {
var _returnType5;
return _regenerator2.default.async(function doubleClick$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_context5.next = 3;
return _regenerator2.default.awrap(this.requestJSON('POST', '/doubleclick'));
case 3:
case 'end':
return _context5.stop();
}
}
}, null, this);
}
/*
* Click and hold the any mouse button at the current location of the mouse cursor
*/
}, {
key: 'buttonDown',
value: function buttonDown() /*: Promise<void>*/ {
var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT;
var _buttonType3, _returnType6;
return _regenerator2.default.async(function buttonDown$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_buttonType3 = _flowRuntime2.default.ref(MouseButton);
_returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('button', _buttonType3).assert(button);
_context6.next = 5;
return _regenerator2.default.awrap(this.requestJSON('POST', '/buttondown', { button: button }));
case 5:
case 'end':
return _context6.stop();
}
}
}, null, this);
}
/*
* 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*/) /*: Promise<void>*/ {
var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT;
var _xOffsetType4, _yOffsetType4, _buttonType4, _returnType7;
return _regenerator2.default.async(function buttonDownAt$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_xOffsetType4 = _flowRuntime2.default.number();
_yOffsetType4 = _flowRuntime2.default.number();
_buttonType4 = _flowRuntime2.default.ref(MouseButton);
_returnType7 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('xOffset', _xOffsetType4).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType4).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType4).assert(button);
_context7.next = 9;
return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset));
case 9:
_context7.next = 11;
return _regenerator2.default.awrap(this.buttonDown(button));
case 11:
case 'end':
return _context7.stop();
}
}
}, null, this);
}
/*
* Releases the mouse button previously held at the current location of the mouse cursor
*/
}, {
key: 'buttonUp',
value: function buttonUp() /*: Promise<void>*/ {
var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT;
var _buttonType5, _returnType8;
return _regenerator2.default.async(function buttonUp$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_buttonType5 = _flowRuntime2.default.ref(MouseButton);
_returnType8 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('button', _buttonType5).assert(button);
_context8.next = 5;
return _regenerator2.default.awrap(this.requestJSON('POST', '/buttonup', { button: button }));
case 5:
case 'end':
return _context8.stop();
}
}
}, null, this);
}
/*
* Releases the mouse button previously held at the current location of the mouse cursor
*/
}, {
key: 'buttonUpAt',
value: function buttonUpAt(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ {
var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT;
var _xOffsetType5, _yOffsetType5, _buttonType6, _returnType9;
return _regenerator2.default.async(function buttonUpAt$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_xOffsetType5 = _flowRuntime2.default.number();
_yOffsetType5 = _flowRuntime2.default.number();
_buttonType6 = _flowRuntime2.default.ref(MouseButton);
_returnType9 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('xOffset', _xOffsetType5).assert(xOffset);
_flowRuntime2.default.param('yOffset', _yOffsetType5).assert(yOffset);
_flowRuntime2.default.param('button', _buttonType6).assert(button);
_context9.next = 9;
return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset));
case 9:
_context9.next = 11;
return _regenerator2.default.awrap(this.buttonUp(button));
case 11:
case 'end':
return _context9.stop();
}
}
}, null, this);
}
}]);
return GlobalMouse;
}(_baseClass2.default);
(0, _addDebugging2.default)(GlobalMouse);
exports.default = GlobalMouse;