UNPKG

cabbie-async

Version:
1,090 lines (846 loc) 41.1 kB
'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 _util = require('util'); var _driver = require('./driver'); var _driver2 = _interopRequireDefault(_driver); var _elementHandle = require('./flow-types/element-handle'); var _selectorTypes = require('./enums/selector-types'); var _selectorTypes2 = _interopRequireDefault(_selectorTypes); 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 _touch = require('./touch'); var _touch2 = _interopRequireDefault(_touch); var _waitFor = require('./utils/wait-for'); var _waitFor2 = _interopRequireDefault(_waitFor); var _flowRuntime = require('flow-runtime'); var _flowRuntime2 = _interopRequireDefault(_flowRuntime); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var SelectorType = _flowRuntime2.default.tdz(function () { return _selectorTypes.SelectorType; }); /* * A representation of a remote element. You can use it to click on, type text into and check the attributes of. * * ```js * const element = await driver.activeWindow.getElement('[data-test-id="my-test-element"]'); * * const elements = await driver.activeWindow.getElements('.some-class-name'); * ``` */ /** * * This file is generated automatically, run npm run build to re-generate. **/ var ElementHandle = _flowRuntime2.default.tdz(function () { return _elementHandle.ElementHandle; }); var Driver = _flowRuntime2.default.tdz(function () { return _driver2.default; }); var Element = function (_BaseClass) { (0, _inherits3.default)(Element, _BaseClass); /* * Utility methods for clicking on the element */ function Element(driver /*: Driver*/, parent /*: Element | Driver*/, selector /*: string*/, elementHandle /*: ElementHandle*/) { (0, _classCallCheck3.default)(this, Element); var _driverType = _flowRuntime2.default.ref(Driver); var _parentType = _flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.ref(Driver)); var _selectorType = _flowRuntime2.default.string(); var _elementHandleType = _flowRuntime2.default.ref(ElementHandle); _flowRuntime2.default.param('driver', _driverType).assert(driver); _flowRuntime2.default.param('parent', _parentType).assert(parent); _flowRuntime2.default.param('selector', _selectorType).assert(selector); _flowRuntime2.default.param('elementHandle', _elementHandleType).assert(elementHandle); var prefix = '/element/' + elementHandle.ELEMENT; var _this = (0, _possibleConstructorReturn3.default)(this, (Element.__proto__ || (0, _getPrototypeOf2.default)(Element)).call(this, driver, prefix)); _this._parent = parent; _this._selector = selector; _this.elementID = elementHandle.ELEMENT; _this.mouse = new _mouse2.default(_this.driver, _this); _this.touch = new _touch2.default(_this.driver, _this); return _this; } /* * Get the value of an attribute. */ /* * Methods for interacting with the element via touch */ /* * The selenium id of the element */ (0, _createClass3.default)(Element, [{ key: 'getAttribute', value: function getAttribute(attribute /*: string*/) /*: Promise<string>*/ { var _attributeType, _returnType; return _regenerator2.default.async(function getAttribute$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _attributeType = _flowRuntime2.default.string(); _returnType = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.string(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.string()))); _flowRuntime2.default.param('attribute', _attributeType).assert(attribute); _context.t0 = _returnType; _context.next = 6; return _regenerator2.default.awrap(this.requestJSON('GET', '/attribute/' + attribute)); case 6: _context.t1 = _context.sent; return _context.abrupt('return', _context.t0.assert.call(_context.t0, _context.t1)); case 8: case 'end': return _context.stop(); } } }, null, this); } /* * Test if the element have a specific class */ }, { key: 'hasClass', value: function hasClass(className /*: string*/) /*: Promise<boolean>*/ { var _classNameType, _returnType2, classNames; return _regenerator2.default.async(function hasClass$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _classNameType = _flowRuntime2.default.string(); _returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _flowRuntime2.default.param('className', _classNameType).assert(className); _context2.next = 5; return _regenerator2.default.awrap(this.getAttribute('class')); case 5: classNames = _context2.sent; return _context2.abrupt('return', _returnType2.assert(!!classNames.match(new RegExp('\\b' + className + '\\b')))); case 7: case 'end': return _context2.stop(); } } }, null, this); } /* * Get the text body of an element. */ }, { key: 'getText', value: function getText() /*: Promise<string>*/ { var _returnType3; return _regenerator2.default.async(function getText$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.string(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.string()))); _context3.t0 = _returnType3; _context3.next = 4; return _regenerator2.default.awrap(this.requestJSON('GET', '/text')); case 4: _context3.t1 = _context3.sent; return _context3.abrupt('return', _context3.t0.assert.call(_context3.t0, _context3.t1)); case 6: case 'end': return _context3.stop(); } } }, null, this); } /* * Get the tag-name of an element. */ }, { key: 'getTagName', value: function getTagName() /*: Promise<string>*/ { var _returnType4; return _regenerator2.default.async(function getTagName$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.string(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.string()))); _context4.t0 = _returnType4; _context4.next = 4; return _regenerator2.default.awrap(this.requestJSON('GET', '/name')); 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); } /* * Query the value of an element's computed CSS property. The CSS property to query * should be specified using the CSS property name, not the JavaScript property name * (e.g. background-color instead of backgroundColor). */ }, { key: 'getCssValue', value: function getCssValue(property /*: string*/) /*: Promise<string>*/ { var _propertyType, _returnType5; return _regenerator2.default.async(function getCssValue$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _propertyType = _flowRuntime2.default.string(); _returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.string(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.string()))); _flowRuntime2.default.param('property', _propertyType).assert(property); _context5.t0 = _returnType5; _context5.next = 6; return _regenerator2.default.awrap(this.requestJSON('GET', '/css/' + property)); case 6: _context5.t1 = _context5.sent; return _context5.abrupt('return', _context5.t0.assert.call(_context5.t0, _context5.t1)); case 8: case 'end': return _context5.stop(); } } }, null, this); } /* * Return true if the element is currently displayed on the page */ }, { key: 'isDisplayed', value: function isDisplayed() /*: Promise<boolean>*/ { var _returnType6; return _regenerator2.default.async(function isDisplayed$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _context6.t0 = _returnType6; _context6.next = 4; return _regenerator2.default.awrap(this.requestJSON('GET', '/displayed')); case 4: _context6.t1 = _context6.sent; return _context6.abrupt('return', _context6.t0.assert.call(_context6.t0, _context6.t1)); case 6: case 'end': return _context6.stop(); } } }, null, this); } /* * Return true if the form element is selected */ }, { key: 'isSelected', value: function isSelected() /*: Promise<boolean>*/ { var _returnType7; return _regenerator2.default.async(function isSelected$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _returnType7 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _context7.t0 = _returnType7; _context7.next = 4; return _regenerator2.default.awrap(this.requestJSON('GET', '/selected')); case 4: _context7.t1 = _context7.sent; return _context7.abrupt('return', _context7.t0.assert.call(_context7.t0, _context7.t1)); case 6: case 'end': return _context7.stop(); } } }, null, this); } /* * Return true if the current element is equal to the supplied element */ }, { key: 'isEqual', value: function isEqual(element /*: Element*/) /*: Promise<boolean>*/ { var _elementType, _returnType8; return _regenerator2.default.async(function isEqual$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _elementType = _flowRuntime2.default.ref(Element); _returnType8 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _flowRuntime2.default.param('element', _elementType).assert(element); _context8.t0 = _returnType8; _context8.next = 6; return _regenerator2.default.awrap(this.requestJSON('GET', '/equals/' + element.elementID)); case 6: _context8.t1 = _context8.sent; return _context8.abrupt('return', _context8.t0.assert.call(_context8.t0, _context8.t1)); case 8: case 'end': return _context8.stop(); } } }, null, this); } /* * Return true if the form element is enabled */ }, { key: 'isEnabled', value: function isEnabled() /*: Promise<boolean>*/ { var _returnType9; return _regenerator2.default.async(function isEnabled$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _returnType9 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _context9.t0 = _returnType9; _context9.next = 4; return _regenerator2.default.awrap(this.requestJSON('GET', '/enabled')); case 4: _context9.t1 = _context9.sent; return _context9.abrupt('return', _context9.t0.assert.call(_context9.t0, _context9.t1)); case 6: case 'end': return _context9.stop(); } } }, null, this); } /* * Return true if the form element is disabled */ }, { key: 'isDisabled', value: function isDisabled() /*: Promise<boolean>*/ { var _returnType10, isEnabled; return _regenerator2.default.async(function isDisabled$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _returnType10 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _context10.next = 3; return _regenerator2.default.awrap(this.isEnabled()); case 3: isEnabled = _context10.sent; return _context10.abrupt('return', _returnType10.assert(!isEnabled)); case 5: case 'end': return _context10.stop(); } } }, null, this); } // todo: uploading files ala wd.Element.sendKeys /* * Type a string of characters into an input */ }, { key: 'sendKeys', value: function sendKeys(str /*: string | Array<string>*/) /*: Promise<void>*/ { var _strType, _returnType11; return _regenerator2.default.async(function sendKeys$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _strType = _flowRuntime2.default.union(_flowRuntime2.default.string(), _flowRuntime2.default.array(_flowRuntime2.default.string())); _returnType11 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('str', _strType).assert(str); _context11.next = 5; return _regenerator2.default.awrap(this.requestJSON('POST', '/value', { value: Array.isArray(str) ? str : [str] })); case 5: case 'end': return _context11.stop(); } } }, null, this); } /* * Clear the value of an input */ }, { key: 'clear', value: function clear() /*: Promise<void>*/ { var _returnType12; return _regenerator2.default.async(function clear$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: _returnType12 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _context12.next = 3; return _regenerator2.default.awrap(this.requestJSON('POST', '/clear')); case 3: case 'end': return _context12.stop(); } } }, null, this); } /* * Submit a form element */ }, { key: 'submit', value: function submit() /*: Promise<void>*/ { var _returnType13; return _regenerator2.default.async(function submit$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: _returnType13 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _context13.next = 3; return _regenerator2.default.awrap(this.requestJSON('POST', '/submit')); case 3: case 'end': return _context13.stop(); } } }, null, this); } /* * Get the size of an element */ }, { key: 'getSize', value: function getSize() /*: Promise<{ width: number; height: number; }>*/ { var _returnType14, size; return _regenerator2.default.async(function getSize$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: _returnType14 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.object(_flowRuntime2.default.property('width', _flowRuntime2.default.number()), _flowRuntime2.default.property('height', _flowRuntime2.default.number())), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.object(_flowRuntime2.default.property('width', _flowRuntime2.default.number()), _flowRuntime2.default.property('height', _flowRuntime2.default.number()))))); _context14.next = 3; return _regenerator2.default.awrap(this.requestJSON('GET', '/size')); case 3: size = _context14.sent; return _context14.abrupt('return', _returnType14.assert({ width: size.width, height: size.height })); case 5: case 'end': return _context14.stop(); } } }, null, this); } /* * Get the position of an element */ }, { key: 'getPosition', value: function getPosition() /*: Promise<{ x: number; y: number; }>*/ { var _returnType15, position; return _regenerator2.default.async(function getPosition$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: _returnType15 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number())), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number()))))); _context15.next = 3; return _regenerator2.default.awrap(this.requestJSON('GET', '/location')); case 3: position = _context15.sent; return _context15.abrupt('return', _returnType15.assert({ x: position.x, y: position.y })); case 5: case 'end': return _context15.stop(); } } }, null, this); } /* * Get the frame of an element */ }, { key: 'getFrame', value: function getFrame() /*: Promise<{ x: number; y: number; width: number; height: number; }>*/ { var _returnType16, position, size; return _regenerator2.default.async(function getFrame$(_context16) { while (1) { switch (_context16.prev = _context16.next) { case 0: _returnType16 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number()), _flowRuntime2.default.property('width', _flowRuntime2.default.number()), _flowRuntime2.default.property('height', _flowRuntime2.default.number())), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number()), _flowRuntime2.default.property('width', _flowRuntime2.default.number()), _flowRuntime2.default.property('height', _flowRuntime2.default.number()))))); _context16.next = 3; return _regenerator2.default.awrap(this.getPosition()); case 3: position = _context16.sent; _context16.next = 6; return _regenerator2.default.awrap(this.getSize()); case 6: size = _context16.sent; return _context16.abrupt('return', _returnType16.assert({ x: position.x, y: position.y, width: size.width, height: size.height })); case 8: case 'end': return _context16.stop(); } } }, null, this); } /* * Get the absolute center of an element */ }, { key: 'getAbsoluteCenter', value: function getAbsoluteCenter() /*: Promise<{ x: number; y: number; }>*/ { var _returnType17, frame; return _regenerator2.default.async(function getAbsoluteCenter$(_context17) { while (1) { switch (_context17.prev = _context17.next) { case 0: _returnType17 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number())), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number()))))); _context17.next = 3; return _regenerator2.default.awrap(this.getFrame()); case 3: frame = _context17.sent; return _context17.abrupt('return', _returnType17.assert({ x: Math.floor(frame.width / 2) + frame.x, y: Math.floor(frame.height / 2) + frame.y })); case 5: case 'end': return _context17.stop(); } } }, null, this); } /* * Get the relative center of an element */ }, { key: 'getRelativeCenter', value: function getRelativeCenter() /*: Promise<{ x: number; y: number; }>*/ { var _returnType18, size; return _regenerator2.default.async(function getRelativeCenter$(_context18) { while (1) { switch (_context18.prev = _context18.next) { case 0: _returnType18 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number())), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.object(_flowRuntime2.default.property('x', _flowRuntime2.default.number()), _flowRuntime2.default.property('y', _flowRuntime2.default.number()))))); _context18.next = 3; return _regenerator2.default.awrap(this.getSize()); case 3: size = _context18.sent; return _context18.abrupt('return', _returnType18.assert({ x: Math.floor(size.width / 2), y: Math.floor(size.height / 2) })); case 5: case 'end': return _context18.stop(); } } }, null, this); } /* * Get an element via a selector. * Will throw an error if the element does not exist. */ }, { key: 'getElement', value: function getElement(selector /*: string*/) /*: Promise<Element>*/ { var _this2 = this; var selectorType /*: SelectorType*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _selectorTypes2.default.CSS; var _selectorType2, _selectorTypeType, _returnType19, elementHandle; return _regenerator2.default.async(function getElement$(_context19) { while (1) { switch (_context19.prev = _context19.next) { case 0: _selectorType2 = _flowRuntime2.default.string(); _selectorTypeType = _flowRuntime2.default.ref(SelectorType); _returnType19 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.ref(Element)))); _flowRuntime2.default.param('selector', _selectorType2).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType).assert(selectorType); _context19.next = 7; return _regenerator2.default.awrap((0, _waitFor2.default)(function () { return _this2.requestJSON('POST', '/element', { using: selectorType, value: selector }); })); case 7: elementHandle = _context19.sent; return _context19.abrupt('return', _returnType19.assert(new Element(this.driver, this, [this._selector, selector].join(' '), elementHandle))); case 9: case 'end': return _context19.stop(); } } }, null, this); } /* * Get an element via a selector. * Will return null if the element does not exist */ }, { key: 'tryGetElement', value: function tryGetElement(selector /*: string*/) /*: Promise<Element | null>*/ { var selectorType /*: SelectorType*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _selectorTypes2.default.CSS; var _selectorType3, _selectorTypeType2, _returnType20, elementHandle; return _regenerator2.default.async(function tryGetElement$(_context20) { while (1) { switch (_context20.prev = _context20.next) { case 0: _selectorType3 = _flowRuntime2.default.string(); _selectorTypeType2 = _flowRuntime2.default.ref(SelectorType); _returnType20 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.null()), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.null())))); _flowRuntime2.default.param('selector', _selectorType3).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType2).assert(selectorType); _context20.prev = 5; _context20.next = 8; return _regenerator2.default.awrap(this.requestJSON('POST', '/element', { using: selectorType, value: selector })); case 8: elementHandle = _context20.sent; return _context20.abrupt('return', _returnType20.assert(new Element(this.driver, this, [this._selector, selector].join(' '), elementHandle))); case 12: _context20.prev = 12; _context20.t0 = _context20['catch'](5); if (!(_context20.t0.code === 'NoSuchElement' || _context20.t0.code === 'ElementNotVisible' || _context20.t0.code === 'ElementIsNotSelectable')) { _context20.next = 16; break; } return _context20.abrupt('return', _returnType20.assert(null)); case 16: throw _context20.t0; case 17: case 'end': return _context20.stop(); } } }, null, this, [[5, 12]]); } /* * Get elements via a selector. */ }, { key: 'getElements', value: function getElements(selector /*: string*/) /*: Promise<Array<Element>>*/ { var _this3 = this; var selectorType /*: SelectorType*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _selectorTypes2.default.CSS; var _selectorType4, _selectorTypeType3, _returnType21, elementHandles; return _regenerator2.default.async(function getElements$(_context21) { while (1) { switch (_context21.prev = _context21.next) { case 0: _selectorType4 = _flowRuntime2.default.string(); _selectorTypeType3 = _flowRuntime2.default.ref(SelectorType); _returnType21 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.array(_flowRuntime2.default.ref(Element)), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.array(_flowRuntime2.default.ref(Element))))); _flowRuntime2.default.param('selector', _selectorType4).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType3).assert(selectorType); _context21.next = 7; return _regenerator2.default.awrap(this.requestJSON('POST', '/elements', { using: selectorType, value: selector })); case 7: elementHandles = _context21.sent; return _context21.abrupt('return', _returnType21.assert(elementHandles.map(function (elementHandle) { return new Element(_this3.driver, _this3, [_this3._selector, selector].join(' '), elementHandle); }))); case 9: case 'end': return _context21.stop(); } } }, null, this); } /* * Get elements by its text content, optionally narrowed down using a selector. * * N.B. this is **much** slower than getting elements by ID or css selector. */ }, { key: 'getElementsByTextContent', value: function getElementsByTextContent(textContent /*: string*/) /*: Promise<Array<Element>>*/ { var selector /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '*'; var selectorType /*: SelectorType*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _selectorTypes2.default.CSS; var _textContentType, _selectorType5, _selectorTypeType4, _returnType22, elements, elementsToReturn, i; return _regenerator2.default.async(function getElementsByTextContent$(_context22) { while (1) { switch (_context22.prev = _context22.next) { case 0: _textContentType = _flowRuntime2.default.string(); _selectorType5 = _flowRuntime2.default.string(); _selectorTypeType4 = _flowRuntime2.default.ref(SelectorType); _returnType22 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.array(_flowRuntime2.default.ref(Element)), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.array(_flowRuntime2.default.ref(Element))))); _flowRuntime2.default.param('textContent', _textContentType).assert(textContent); _flowRuntime2.default.param('selector', _selectorType5).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType4).assert(selectorType); if (selector === 'a' && (selectorType === _selectorTypes2.default.CSS || selectorType === _selectorTypes2.default.TAG)) { selector = _selectorType5.assert(textContent); selectorType = _selectorTypeType4.assert(_selectorTypes2.default.PARTIAL_LINK_TEXT); } textContent = _textContentType.assert(textContent.trim()); _context22.next = 11; return _regenerator2.default.awrap(this.getElements(selector, selectorType)); case 11: elements = _context22.sent; elementsToReturn = []; i = 0; case 14: if (!(i < elements.length)) { _context22.next = 24; break; } _context22.t0 = textContent; _context22.next = 18; return _regenerator2.default.awrap(elements[i].getText()); case 18: _context22.t1 = _context22.sent.trim(); if (!(_context22.t0 === _context22.t1)) { _context22.next = 21; break; } elementsToReturn.push(elements[i]); case 21: i++; _context22.next = 14; break; case 24: return _context22.abrupt('return', _returnType22.assert(elementsToReturn)); case 25: case 'end': return _context22.stop(); } } }, null, this); } /* * Get elements by its text content, optionally narrowed down using a selector. * * N.B. this is **much** slower than getting elements by ID or css selector. */ }, { key: 'getElementByTextContent', value: function getElementByTextContent(textContent /*: string*/) /*: Promise<Element>*/ { var _this4 = this; var selector /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '*'; var selectorType /*: SelectorType*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _selectorTypes2.default.CSS; var _textContentType2, _selectorType6, _selectorTypeType5, _returnType23, element, err; return _regenerator2.default.async(function getElementByTextContent$(_context23) { while (1) { switch (_context23.prev = _context23.next) { case 0: _textContentType2 = _flowRuntime2.default.string(); _selectorType6 = _flowRuntime2.default.string(); _selectorTypeType5 = _flowRuntime2.default.ref(SelectorType); _returnType23 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.ref(Element)))); _flowRuntime2.default.param('textContent', _textContentType2).assert(textContent); _flowRuntime2.default.param('selector', _selectorType6).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType5).assert(selectorType); _context23.next = 9; return _regenerator2.default.awrap((0, _waitFor2.default)(function () { return _this4.tryGetElementByTextContent(textContent, selector, selectorType); })); case 9: element = _context23.sent; if (!element) { _context23.next = 12; break; } return _context23.abrupt('return', _returnType23.assert(element)); case 12: err = new Error('Could not find an element with the text content: ' + textContent); err.name = 'NoSuchElement'; _flowRuntime2.default.any().assert(err).code = 'NoSuchElement'; throw err; case 16: case 'end': return _context23.stop(); } } }, null, this); } /* * Get elements by its text content, optionally narrowed down using a selector. * * N.B. this is **much** slower than getting elements by ID or css selector. */ }, { key: 'tryGetElementByTextContent', value: function tryGetElementByTextContent(textContent /*: string*/) /*: Promise<Element | null>*/ { var selector /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '*'; var selectorType /*: SelectorType*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _selectorTypes2.default.CSS; var _textContentType3, _selectorType7, _selectorTypeType6, _returnType24, elements, i; return _regenerator2.default.async(function tryGetElementByTextContent$(_context24) { while (1) { switch (_context24.prev = _context24.next) { case 0: _textContentType3 = _flowRuntime2.default.string(); _selectorType7 = _flowRuntime2.default.string(); _selectorTypeType6 = _flowRuntime2.default.ref(SelectorType); _returnType24 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.null()), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.union(_flowRuntime2.default.ref(Element), _flowRuntime2.default.null())))); _flowRuntime2.default.param('textContent', _textContentType3).assert(textContent); _flowRuntime2.default.param('selector', _selectorType7).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType6).assert(selectorType); if (selector === 'a' && (selectorType === _selectorTypes2.default.CSS || selectorType === _selectorTypes2.default.TAG)) { selector = _selectorType7.assert(textContent); selectorType = _selectorTypeType6.assert(_selectorTypes2.default.PARTIAL_LINK_TEXT); } textContent = _textContentType3.assert(textContent.trim().toLowerCase()); _context24.next = 11; return _regenerator2.default.awrap(this.getElements(selector, selectorType)); case 11: elements = _context24.sent; i = 0; case 13: if (!(i < elements.length)) { _context24.next = 23; break; } _context24.t0 = textContent; _context24.next = 17; return _regenerator2.default.awrap(elements[i].getText()); case 17: _context24.t1 = _context24.sent.trim().toLowerCase(); if (!(_context24.t0 === _context24.t1)) { _context24.next = 20; break; } return _context24.abrupt('return', _returnType24.assert(elements[i])); case 20: i++; _context24.next = 13; break; case 23: return _context24.abrupt('return', _returnType24.assert(null)); case 24: case 'end': return _context24.stop(); } } }, null, this); } /* * Does a specific element exist? */ }, { key: 'hasElement', value: function hasElement(selector /*: string*/) /*: Promise<boolean>*/ { var selectorType /*: SelectorType*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _selectorTypes2.default.CSS; var _selectorType8, _selectorTypeType7, _returnType25, elements; return _regenerator2.default.async(function hasElement$(_context25) { while (1) { switch (_context25.prev = _context25.next) { case 0: _selectorType8 = _flowRuntime2.default.string(); _selectorTypeType7 = _flowRuntime2.default.ref(SelectorType); _returnType25 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.boolean(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.boolean()))); _flowRuntime2.default.param('selector', _selectorType8).assert(selector); _flowRuntime2.default.param('selectorType', _selectorTypeType7).assert(selectorType); _context25.next = 7; return _regenerator2.default.awrap(this.getElements(selector, selectorType)); case 7: elements = _context25.sent; return _context25.abrupt('return', _returnType25.assert(elements.length > 0)); case 9: case 'end': return _context25.stop(); } } }, null, this); } }]); return Element; }(_baseClass2.default); (0, _addDebugging2.default)(Element, { inspect: function inspect(obj, depth, options) { return 'Element(' + (0, _util.inspect)(obj._selector, options) + ')'; } }); exports.default = Element;