@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
73 lines • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.O3rElement = void 0;
exports.getPlainText = getPlainText;
/**
* 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.
*/
class O3rElement {
constructor(sourceElement) {
this.sourceElement = sourceElement instanceof O3rElement
? { element: sourceElement.sourceElement.element, page: sourceElement.sourceElement.page }
: sourceElement;
}
/** @inheritdoc */
getText() {
return this.sourceElement.element.innerText();
}
/** @inheritdoc */
async getPlainText() {
return getPlainText(await this.getText());
}
/** @inheritdoc */
getInnerHTML() {
return this.sourceElement.element.innerHTML();
}
/** @inheritdoc */
mouseOver() {
return this.sourceElement.element.hover();
}
/** @inheritdoc */
async getValue() {
try {
return await this.sourceElement.element.inputValue();
}
catch {
// eslint-disable-next-line no-console -- no other logger available
console.warn('Failed to retrieve input value');
const valueByAttribute = await this.sourceElement.element.getAttribute('value');
return valueByAttribute === null ? undefined : valueByAttribute;
}
}
/** @inheritdoc */
async setValue(input) {
await this.sourceElement.element.fill(input);
await this.sourceElement.element.press('Tab');
}
/** @inheritdoc */
async clearValue() {
await this.sourceElement.element.fill('');
}
/** @inheritdoc */
click() {
return this.sourceElement.element.click();
}
/** @inheritdoc */
isVisible() {
return this.sourceElement.element.isVisible();
}
/** @inheritdoc */
async getAttribute(attributeName) {
const attribute = await this.sourceElement.element.getAttribute(attributeName);
return attribute === null ? undefined : attribute;
}
}
exports.O3rElement = O3rElement;
//# sourceMappingURL=element.js.map