UNPKG

@o3r/testing

Version:

The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.

145 lines 6.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rElement = void 0; var tslib_1 = require("tslib"); var protractor_1 = require("protractor"); var ptor_1 = require("protractor/built/ptor"); var protractor_2 = require("../../tools/protractor"); var utils_1 = require("./utils"); /** * Implementation dedicated to protractor. * @deprecated Will be removed in v13, please use Playwright instead */ var O3rElement = /** @class */ (function () { function O3rElement(sourceElement) { this.sourceElement = sourceElement instanceof O3rElement ? sourceElement.sourceElement : sourceElement; } /** @inheritdoc */ O3rElement.prototype.getText = function () { return (0, utils_1.convertPromise)(this.sourceElement.getText()); }; /** @inheritdoc */ O3rElement.prototype.getPlainText = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var innerText; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getText()]; case 1: innerText = _a.sent(); return [2 /*return*/, Promise.resolve(innerText ? innerText.replace(/\r\n|\r|\n/g, ' ').replace(/\s\s+/g, ' ').trim() : undefined)]; } }); }); }; /** @inheritdoc */ O3rElement.prototype.getInnerHTML = function () { return (0, utils_1.convertPromise)(this.sourceElement.getInnerHtml()); }; /** @inheritdoc */ O3rElement.prototype.mouseOver = function () { return (0, utils_1.convertPromise)(protractor_1.browser .actions() .mouseMove(this.sourceElement) .perform()); }; /** @inheritdoc */ O3rElement.prototype.getValue = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var value; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.sourceElement.getAttribute('value')]; case 1: value = _a.sent(); return [2 /*return*/, value === null ? undefined : value]; } }); }); }; /** @inheritdoc */ O3rElement.prototype.setValue = function (input) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: // Clears the value in the field return [4 /*yield*/, this.clearValue()]; case 1: // Clears the value in the field _a.sent(); return [4 /*yield*/, this.sourceElement.sendKeys(input)]; case 2: _a.sent(); return [4 /*yield*/, this.sourceElement.sendKeys(ptor_1.protractor.Key.TAB)]; case 3: _a.sent(); return [2 /*return*/, (0, protractor_2.waitForOtterStable)()]; } }); }); }; /** @inheritdoc */ O3rElement.prototype.clearValue = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var currentValue; var _a; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, this.getValue()]; case 1: currentValue = _b.sent(); if (!(currentValue !== undefined)) return [3 /*break*/, 3]; // eslint-disable-next-line unicorn/no-new-array -- Required for array initialization purpose return [4 /*yield*/, (_a = this.sourceElement).sendKeys.apply(_a, (new Array(currentValue.length + 1).fill(ptor_1.protractor.Key.BACK_SPACE)))]; case 2: // eslint-disable-next-line unicorn/no-new-array -- Required for array initialization purpose _b.sent(); _b.label = 3; case 3: return [2 /*return*/]; } }); }); }; /** @inheritdoc */ O3rElement.prototype.click = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.sourceElement.click()]; case 1: _a.sent(); return [2 /*return*/, (0, protractor_2.waitForOtterStable)()]; } }); }); }; /** @inheritdoc */ O3rElement.prototype.isVisible = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.sourceElement.isDisplayed()]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** @inheritdoc */ O3rElement.prototype.getAttribute = function (attributeName) { return tslib_1.__awaiter(this, void 0, void 0, function () { var attribute; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.sourceElement.getAttribute(attributeName)]; case 1: attribute = _a.sent(); return [2 /*return*/, attribute === null ? undefined : attribute]; } }); }); }; return O3rElement; }()); exports.O3rElement = O3rElement; //# sourceMappingURL=element.js.map