cabbie-sync
Version:
A synchronous webdriver client
185 lines (128 loc) • 4.99 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 _options = require('./flow-types/options');
var _driver = require('./driver');
var _driver2 = _interopRequireDefault(_driver);
var _url = require('url');
var _addDebugging = require('./add-debugging');
var _addDebugging2 = _interopRequireDefault(_addDebugging);
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 }; }
/**
*
* This file is generated automatically, run npm run build to re-generate.
**/
var Driver = _flowRuntime2.default.tdz(function () {
return _driver2.default;
});
/*
* Navigation object
*
* @deprecated These methods all now live directly on the "ActiveWindow" object.
*/
var Options = _flowRuntime2.default.tdz(function () {
return _options.Options;
});
var Navigator = function (_BaseClass) {
(0, _inherits3.default)(Navigator, _BaseClass);
function Navigator(driver /*: Driver*/, options /*: Options*/) {
(0, _classCallCheck3.default)(this, Navigator);
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, (Navigator.__proto__ || (0, _getPrototypeOf2.default)(Navigator)).call(this, driver));
_this._options = options;
return _this;
}
/*
* Navigate forwards in the browser history, if possible.
*/
(0, _createClass3.default)(Navigator, [{
key: 'forward',
value: function forward() /*: void*/ {
var _returnType = _flowRuntime2.default.return(_flowRuntime2.default.void());
this.requestJSON('POST', '/forward');
}
/*
* Navigate backwards in the browser history, if possible.
*/
}, {
key: 'backward',
value: function backward() /*: void*/ {
var _returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.void());
this.requestJSON('POST', '/back');
}
/*
* Refreshes the browser
*/
}, {
key: 'refresh',
value: function refresh() /*: void*/ {
var _returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.void());
this.requestJSON('POST', '/refresh');
}
/*
* Get the current url that the browser is displaying
*/
}, {
key: 'getUrl',
value: function getUrl() /*: string*/ {
var _returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.string());
return _returnType4.assert(this.requestJSON('GET', '/url'));
}
/*
* Navigates the browser to the specified path
*
* - if `path` begins with a "/" it is relative to `options.base`
* - if `path` begins with "http" it is absolute
* - otherwise it is relative to the current path
*/
}, {
key: 'navigateTo',
value: function navigateTo(path /*: string*/) /*: void*/ {
var _pathType = _flowRuntime2.default.string();
var _returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.void());
_flowRuntime2.default.param('path', _pathType).assert(path);
if (path[0] === '/') {
var base = this._options.base;
if (!base) {
throw new Error('You must provide a "base" option to use urls starting with "/"');
}
path = _pathType.assert(base.replace(/\/$/, '') + path);
} else if (path.indexOf('http') !== 0) {
var _base = this.getUrl();
this.navigateTo((0, _url.resolve)(_base, path));
return _returnType5.assert();
}
this.driver.requestJSON('POST', '/url', { url: path });
}
}]);
return Navigator;
}(_baseClass2.default);
/*
* Navigates the browser to the specified path
*
* Alias for `navigateTo`
*
* @method setUrl
* @param {String} path
*/
_flowRuntime2.default.any().assert(Navigator.prototype).setUrl = Navigator.prototype.navigateTo;
(0, _addDebugging2.default)(Navigator);
exports.default = Navigator;