cabbie-async
Version:
An asynchronous webdriver client
296 lines (210 loc) • 9.83 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 _browserOrientations = require('./enums/browser-orientations');
var _driver = require('./driver');
var _driver2 = _interopRequireDefault(_driver);
var _options = require('./flow-types/options');
var _activeWindow = require('./active-window');
var _activeWindow2 = _interopRequireDefault(_activeWindow);
var _addDebugging = require('./add-debugging');
var _addDebugging2 = _interopRequireDefault(_addDebugging);
var _baseClass = require('./base-class');
var _baseClass2 = _interopRequireDefault(_baseClass);
var _cookieStorage = require('./cookie-storage');
var _cookieStorage2 = _interopRequireDefault(_cookieStorage);
var _ime = require('./ime');
var _ime2 = _interopRequireDefault(_ime);
var _localStorage = require('./local-storage');
var _localStorage2 = _interopRequireDefault(_localStorage);
var _sessionStorage = require('./session-storage');
var _sessionStorage2 = _interopRequireDefault(_sessionStorage);
var _windowHandle = require('./window-handle');
var _windowHandle2 = _interopRequireDefault(_windowHandle);
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 Options = _flowRuntime2.default.tdz(function () {
return _options.Options;
});
/*
* Browser accessor class
*/
var Driver = _flowRuntime2.default.tdz(function () {
return _driver2.default;
});
var BrowserOrientation = _flowRuntime2.default.tdz(function () {
return _browserOrientations.BrowserOrientation;
});
var Browser = function (_BaseClass) {
(0, _inherits3.default)(Browser, _BaseClass);
/*
* Get the Local-Storage object.
*/
/*
* Get the IME object.
*/
function Browser(driver /*: Driver*/, options /*: Options*/) {
(0, _classCallCheck3.default)(this, Browser);
var _driverType = _flowRuntime2.default.ref(Driver);
var _optionsType = _flowRuntime2.default.ref(Options);
_flowRuntime2.default.param('driver', _driverType).assert(driver);
_flowRuntime2.default.param('options', _optionsType).assert(options);
var _this = (0, _possibleConstructorReturn3.default)(this, (Browser.__proto__ || (0, _getPrototypeOf2.default)(Browser)).call(this, driver));
_this.activeWindow = new _activeWindow2.default(_this.driver, options);
_this.ime = new _ime2.default(_this.driver);
_this.cookieStorage = new _cookieStorage2.default(_this.driver);
_this.localStorage = new _localStorage2.default(_this.driver);
_this.sessionStorage = new _sessionStorage2.default(_this.driver);
return _this;
}
/*
* Get an array of windows for all available windows
*/
/*
* Get the Session-Storage object.
*/
/*
* Get the Cookie-Storage object.
*/
/*
* The currently active window. This has most of the methods to interact with
* the the current page.
*/
(0, _createClass3.default)(Browser, [{
key: 'getWindows',
value: function getWindows() /*: Promise<Array<WindowHandle>>*/ {
var _this2 = this;
var _returnType, windowHandles;
return _regenerator2.default.async(function getWindows$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_returnType = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.array(_flowRuntime2.default.ref(_windowHandle2.default)), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.array(_flowRuntime2.default.ref(_windowHandle2.default)))));
_context.next = 3;
return _regenerator2.default.awrap(this.requestJSON('GET', '/window_handles'));
case 3:
windowHandles = _context.sent;
return _context.abrupt('return', _returnType.assert(windowHandles.map(function (windowHandle) {
return new _windowHandle2.default(_this2.driver, windowHandle);
})));
case 5:
case 'end':
return _context.stop();
}
}
}, null, this);
}
/*
* Get the current browser orientation
*/
}, {
key: 'getOrientation',
value: function getOrientation() /*: Promise<BrowserOrientation>*/ {
var _returnType2;
return _regenerator2.default.async(function getOrientation$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.ref(BrowserOrientation), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.ref(BrowserOrientation))));
return _context2.abrupt('return', _returnType2.assert(this.requestJSON('GET', '/orientation')));
case 2:
case 'end':
return _context2.stop();
}
}
}, null, this);
}
/*
* Get the current browser orientation
*/
}, {
key: 'setOrientation',
value: function setOrientation(orientation /*: BrowserOrientation*/) /*: Promise<void>*/ {
var _orientationType, _returnType3;
return _regenerator2.default.async(function setOrientation$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_orientationType = _flowRuntime2.default.ref(BrowserOrientation);
_returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('orientation', _orientationType).assert(orientation);
_context3.next = 5;
return _regenerator2.default.awrap(this.requestJSON('POST', '/orientation', { orientation: orientation }));
case 5:
case 'end':
return _context3.stop();
}
}
}, null, this);
}
/*
* Get the current geo location
*/
}, {
key: 'getGeoLocation',
value: function getGeoLocation() /*: Promise<{ latitude: number; longitude: number; altitude: number; }>*/ {
var _returnType4;
return _regenerator2.default.async(function getGeoLocation$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.object(_flowRuntime2.default.property('latitude', _flowRuntime2.default.number()), _flowRuntime2.default.property('longitude', _flowRuntime2.default.number()), _flowRuntime2.default.property('altitude', _flowRuntime2.default.number())), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.object(_flowRuntime2.default.property('latitude', _flowRuntime2.default.number()), _flowRuntime2.default.property('longitude', _flowRuntime2.default.number()), _flowRuntime2.default.property('altitude', _flowRuntime2.default.number())))));
_context4.t0 = _returnType4;
_context4.next = 4;
return _regenerator2.default.awrap(this.requestJSON('GET', '/location'));
case 4:
_context4.t1 = _context4.sent;
return _context4.abrupt('return', _context4.t0.assert.call(_context4.t0, _context4.t1));
case 6:
case 'end':
return _context4.stop();
}
}
}, null, this);
}
/*
* Set the current geo location
*/
}, {
key: 'setGeoLocation',
value: function setGeoLocation(loc /*: { latitude: number; longitude: number; altitude: number; }*/) /*: Promise<void>*/ {
var _locType, _returnType5;
return _regenerator2.default.async(function setGeoLocation$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_locType = _flowRuntime2.default.object(_flowRuntime2.default.property('latitude', _flowRuntime2.default.number()), _flowRuntime2.default.property('longitude', _flowRuntime2.default.number()), _flowRuntime2.default.property('altitude', _flowRuntime2.default.number()));
_returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void())));
_flowRuntime2.default.param('loc', _locType).assert(loc);
_context5.next = 5;
return _regenerator2.default.awrap(this.requestJSON('POST', '/location', loc));
case 5:
case 'end':
return _context5.stop();
}
}
}, null, this);
}
}]);
return Browser;
}(_baseClass2.default);
(0, _addDebugging2.default)(Browser);
exports.default = Browser;