@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
125 lines • 4.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.O3rElement = void 0;
exports.getPlainText = getPlainText;
var tslib_1 = require("tslib");
/**
* Remove text formatting (endline etc.) and return the content.
* @param innerText
*/
function getPlainText(innerText) {
return innerText ? innerText.replace(/\r\n|\r|\n/g, ' ').replace(/\s\s+/g, ' ').trim() : undefined;
}
/**
* Implementation dedicated to Playwright.
*/
var O3rElement = /** @class */ (function () {
function O3rElement(sourceElement) {
this.sourceElement = sourceElement instanceof O3rElement
? { element: sourceElement.sourceElement.element, page: sourceElement.sourceElement.page }
: sourceElement;
}
/** @inheritdoc */
O3rElement.prototype.getText = function () {
return this.sourceElement.element.innerText();
};
/** @inheritdoc */
O3rElement.prototype.getPlainText = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = getPlainText;
return [4 /*yield*/, this.getText()];
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
}
});
});
};
/** @inheritdoc */
O3rElement.prototype.getInnerHTML = function () {
return this.sourceElement.element.innerHTML();
};
/** @inheritdoc */
O3rElement.prototype.mouseOver = function () {
return this.sourceElement.element.hover();
};
/** @inheritdoc */
O3rElement.prototype.getValue = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, valueByAttribute;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 2, , 4]);
return [4 /*yield*/, this.sourceElement.element.inputValue()];
case 1: return [2 /*return*/, _b.sent()];
case 2:
_a = _b.sent();
// eslint-disable-next-line no-console -- no other logger available
console.warn('Failed to retrieve input value');
return [4 /*yield*/, this.sourceElement.element.getAttribute('value')];
case 3:
valueByAttribute = _b.sent();
return [2 /*return*/, valueByAttribute === null ? undefined : valueByAttribute];
case 4: return [2 /*return*/];
}
});
});
};
/** @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: return [4 /*yield*/, this.sourceElement.element.fill(input)];
case 1:
_a.sent();
return [4 /*yield*/, this.sourceElement.element.press('Tab')];
case 2:
_a.sent();
return [2 /*return*/];
}
});
});
};
/** @inheritdoc */
O3rElement.prototype.clearValue = 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.element.fill('')];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/** @inheritdoc */
O3rElement.prototype.click = function () {
return this.sourceElement.element.click();
};
/** @inheritdoc */
O3rElement.prototype.isVisible = function () {
return this.sourceElement.element.isVisible();
};
/** @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.element.getAttribute(attributeName)];
case 1:
attribute = _a.sent();
return [2 /*return*/, attribute === null ? undefined : attribute];
}
});
});
};
return O3rElement;
}());
exports.O3rElement = O3rElement;
//# sourceMappingURL=element.js.map