cabbie-async
Version:
An asynchronous webdriver client
327 lines (240 loc) • 11.7 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TimeOutsConfig = exports.TimeoutValue = undefined;
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
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 _timeOutTypes = require('./enums/time-out-types');
var _timeOutTypes2 = _interopRequireDefault(_timeOutTypes);
var _driver = require('./driver');
var _driver2 = _interopRequireDefault(_driver);
var _addDebugging = require('./add-debugging');
var _addDebugging2 = _interopRequireDefault(_addDebugging);
var _ms = require('ms');
var _ms2 = _interopRequireDefault(_ms);
var _baseClass = require('./base-class');
var _baseClass2 = _interopRequireDefault(_baseClass);
var _flowRuntime = require('flow-runtime');
var _flowRuntime2 = _interopRequireDefault(_flowRuntime);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Driver = _flowRuntime2.default.tdz(function () {
return _driver2.default;
}); /**
*
* This file is generated automatically, run npm run build to re-generate.
**/
var TimeOutType = _flowRuntime2.default.tdz(function () {
return _timeOutTypes.TimeOutType;
});
var TimeoutValue = exports.TimeoutValue = _flowRuntime2.default.type('TimeoutValue', _flowRuntime2.default.union(_flowRuntime2.default.number(), _flowRuntime2.default.string()));
var TimeOutsConfig = exports.TimeOutsConfig = _flowRuntime2.default.type('TimeOutsConfig', _flowRuntime2.default.object(_flowRuntime2.default.property('script', _flowRuntime2.default.union(TimeoutValue, TimeoutValue, TimeoutValue, TimeoutValue), true)));
/*
* Managing time-out
*/
var TimeOut = function (_BaseClass) {
(0, _inherits3.default)(TimeOut, _BaseClass);
function TimeOut(driver /*: Driver*/) {
(0, _classCallCheck3.default)(this, TimeOut);
var _driverType = _flowRuntime2.default.ref(Driver);
_flowRuntime2.default.param('driver', _driverType).assert(driver);
return (0, _possibleConstructorReturn3.default)(this, (TimeOut.__proto__ || (0, _getPrototypeOf2.default)(TimeOut)).call(this, driver, '/timeouts'));
}
/*
* Set a time-out
*/
(0, _createClass3.default)(TimeOut, [{
key: 'setTimeOut',
value: function setTimeOut(timeOutType /*: TimeOutType*/, ms /*: TimeoutValue*/) /*: Promise<void>*/ {
var _timeOutTypeType, _msType, _returnType;
return _regenerator2.default.async(function setTimeOut$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_timeOutTypeType = _flowRuntime2.default.ref(TimeOutType);
_msType = TimeoutValue;
_returnType = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('timeOutType', _timeOutTypeType).assert(timeOutType);
_flowRuntime2.default.param('ms', _msType).assert(ms);
_context.t0 = timeOutType;
_context.next = _context.t0 === _timeOutTypes2.default.SCRIPT ? 8 : _context.t0 === _timeOutTypes2.default.ASYNC_SCRIPT ? 11 : _context.t0 === _timeOutTypes2.default.PAGE_LOAD ? 14 : _context.t0 === _timeOutTypes2.default.IMPLICIT ? 17 : 20;
break;
case 8:
_context.next = 10;
return _regenerator2.default.awrap(this.setScriptTimeOut(ms));
case 10:
return _context.abrupt('break', 21);
case 11:
_context.next = 13;
return _regenerator2.default.awrap(this.setAsyncScriptTimeOut(ms));
case 13:
return _context.abrupt('break', 21);
case 14:
_context.next = 16;
return _regenerator2.default.awrap(this.setPageLoadTimeOut(ms));
case 16:
return _context.abrupt('break', 21);
case 17:
_context.next = 19;
return _regenerator2.default.awrap(this.setImplicitTimeOut(ms));
case 19:
return _context.abrupt('break', 21);
case 20:
throw new Error('Invalid timeout type ' + (0, _stringify2.default)(timeOutType) + ', expected "script", "page load", "implicit" or "async"');
case 21:
case 'end':
return _context.stop();
}
}
}, null, this);
}
/*
* Set multiple time-outs at once
*/
}, {
key: 'setTimeOuts',
value: function setTimeOuts(timeOuts /*: TimeOutsConfig*/) /*: Promise<void>*/ {
var _timeOutsType, _returnType2;
return _regenerator2.default.async(function setTimeOuts$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_timeOutsType = TimeOutsConfig;
_returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('timeOuts', _timeOutsType).assert(timeOuts);
if (timeOuts['script'] != null) {
this.setTimeOut('script', timeOuts['script']);
}
if (timeOuts['implicit'] != null) {
this.setTimeOut('implicit', timeOuts['implicit']);
}
if (timeOuts['async'] != null) {
this.setTimeOut('async', timeOuts['async']);
}
if (timeOuts['page load'] != null) {
this.setTimeOut('page load', timeOuts['page load']);
}
case 7:
case 'end':
return _context2.stop();
}
}
}, null, this);
}
/*
* Set the amount of time, in milliseconds, that scripts are permitted
* to run before they are aborted and a "Timeout" error is returned to the client.
*/
}, {
key: 'setScriptTimeOut',
value: function setScriptTimeOut(timeout /*: TimeoutValue*/) /*: Promise<void>*/ {
var _timeoutType, _returnType3;
return _regenerator2.default.async(function setScriptTimeOut$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_timeoutType = TimeoutValue;
_returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('timeout', _timeoutType).assert(timeout);
timeout = _timeoutType.assert((0, _ms2.default)(timeout.toString()));
_context3.next = 6;
return _regenerator2.default.awrap(this.requestJSON('POST', '', { type: _timeOutTypes2.default.SCRIPT, ms: timeout }));
case 6:
case 'end':
return _context3.stop();
}
}
}, null, this);
}
/*
* Set the amount of time, in milliseconds, that asynchronous scripts are permitted
* to run before they are aborted and a "Timeout" error is returned to the client.
*/
}, {
key: 'setAsyncScriptTimeOut',
value: function setAsyncScriptTimeOut(timeout /*: TimeoutValue*/) /*: Promise<void>*/ {
var _timeoutType2, _returnType4;
return _regenerator2.default.async(function setAsyncScriptTimeOut$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_timeoutType2 = TimeoutValue;
_returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('timeout', _timeoutType2).assert(timeout);
timeout = _timeoutType2.assert((0, _ms2.default)(timeout.toString()));
_context4.next = 6;
return _regenerator2.default.awrap(this.requestJSON('POST', '/async_script', { ms: timeout }));
case 6:
case 'end':
return _context4.stop();
}
}
}, null, this);
}
/*
* Set the amount of time, in milliseconds, that a page is permitted to be loaded
* before they it is aborted and a "Timeout" error is returned to the client.
*/
}, {
key: 'setPageLoadTimeOut',
value: function setPageLoadTimeOut(timeout /*: TimeoutValue*/) /*: Promise<void>*/ {
var _timeoutType3, _returnType5;
return _regenerator2.default.async(function setPageLoadTimeOut$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_timeoutType3 = TimeoutValue;
_returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('timeout', _timeoutType3).assert(timeout);
timeout = _timeoutType3.assert((0, _ms2.default)(timeout.toString()));
_context5.next = 6;
return _regenerator2.default.awrap(this.requestJSON('POST', '', { type: _timeOutTypes2.default.PAGE_LOAD, ms: timeout }));
case 6:
case 'end':
return _context5.stop();
}
}
}, null, this);
}
/*
* Set the amount of time, in milliseconds, that scripts executed are permitted
* to run before they are aborted and a "Timeout" error is returned to the client.
*/
}, {
key: 'setImplicitTimeOut',
value: function setImplicitTimeOut(timeout /*: TimeoutValue*/) /*: Promise<void>*/ {
var _timeoutType4, _returnType6;
return _regenerator2.default.async(function setImplicitTimeOut$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_timeoutType4 = TimeoutValue;
_returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('timeout', _timeoutType4).assert(timeout);
timeout = _timeoutType4.assert((0, _ms2.default)(timeout.toString()));
_context6.next = 6;
return _regenerator2.default.awrap(this.requestJSON('POST', '', { type: _timeOutTypes2.default.IMPLICIT, ms: timeout }));
case 6:
case 'end':
return _context6.stop();
}
}
}, null, this);
}
}]);
return TimeOut;
}(_baseClass2.default);
(0, _addDebugging2.default)(TimeOut);
exports.default = TimeOut;