UNPKG

cybernaut

Version:

Reliable, zero configuration end-to-end testing in BDD-style.

149 lines 5.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const selenium_webdriver_1 = require("selenium-webdriver"); const utils_1 = require("./utils"); class Element { constructor(selector) { this.selector = selector; } get tagName() { return { description: { template: 'tag name of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return element.getTagName(); }) }; } get text() { return { description: { template: 'text of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return element.getText(); }) }; } get visibility() { return { description: { template: 'visibility of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return element.isDisplayed(); }) }; } get x() { return { description: { template: 'x-position of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return (yield element.getLocation()).x; }) }; } get y() { return { description: { template: 'y-position of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return (yield element.getLocation()).y; }) }; } get width() { return { description: { template: 'width of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return (yield element.getSize()).width; }) }; } get height() { return { description: { template: 'height of element {}', args: [this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return (yield element.getSize()).height; }) }; } cssValue(cssName) { return { description: { template: 'css value {} of element {}', args: [cssName, this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return element.getCssValue(cssName); }) }; } propertyValue(propertyName) { return { description: { template: 'property value {} of element {}', args: [propertyName, this.selector] }, get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); return element.getAttribute(propertyName); }) }; } clearValue() { return { description: { template: 'clear value of element {}', args: [this.selector] }, perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); yield element.clear(); }) }; } click() { return { description: { template: 'click on element {}', args: [this.selector] }, perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); yield element.click(); }) }; } sendKeys(...keys) { return { description: { template: 'send keys {} to element {}', args: [keys.map(utils_1.translate), this.selector] }, perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); yield element.sendKeys(...keys); }) }; } submitForm() { return { description: { template: 'submit form containing element {}', args: [this.selector] }, perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { const element = yield driver.findElement(selenium_webdriver_1.By.css(this.selector)); yield element.submit(); }) }; } } exports.Element = Element; //# sourceMappingURL=element.js.map