@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
89 lines • 3.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.O3rSliderElement = void 0;
const element_1 = require("../element");
/**
* Implementation dedicated to Playwright.
*/
class O3rSliderElement extends element_1.O3rElement {
constructor(sourceElement, trackSelector, thumbSelector) {
super(sourceElement);
this.trackSelector = trackSelector;
this.thumbSelector = thumbSelector;
}
async getInputElement() {
try {
const subElement = this.sourceElement.element.locator('input[type="range"]');
if (await subElement.count()) {
return subElement.first();
}
return this.sourceElement.element;
}
catch {
return this.sourceElement.element;
}
}
async getTrackElement() {
if (!this.trackSelector) {
return this.sourceElement.element;
}
try {
const subElement = this.sourceElement.element.locator(this.trackSelector);
if (await subElement.count()) {
return subElement.first();
}
return this.sourceElement.element;
}
catch {
return this.sourceElement.element;
}
}
async getThumbElement() {
if (!this.thumbSelector) {
return this.sourceElement.element;
}
try {
const subElement = this.sourceElement.element.locator(this.thumbSelector);
if (await subElement.count()) {
return subElement.first();
}
return this.sourceElement.element;
}
catch {
return this.sourceElement.element;
}
}
/** @inheritdoc */
async setValue(value) {
const trackElement = await this.getTrackElement();
const trackBoundingBox = await trackElement.boundingBox();
const thumbElement = await this.getThumbElement();
const inputElement = await this.getInputElement();
const thumbBoundingBox = await thumbElement.boundingBox();
if (!trackBoundingBox || !thumbBoundingBox) {
return;
}
const startPosition = {
x: thumbBoundingBox.x + thumbBoundingBox.width / 2,
y: thumbBoundingBox.y + thumbBoundingBox.height / 2
};
await this.sourceElement.page.mouse.move(startPosition.x, startPosition.y);
await this.sourceElement.page.mouse.down();
const maxAttribute = await inputElement.getAttribute('max');
const max = maxAttribute ? +maxAttribute : 100;
const minAttribute = await inputElement.getAttribute('min');
const min = minAttribute ? +minAttribute : 0;
const percent = (Math.max(min, Math.min(+value, max)) - min) / (max - min);
await this.sourceElement.page.mouse.move(trackBoundingBox.x + Math.round(trackBoundingBox.width * percent), trackBoundingBox.y + trackBoundingBox.height / 2);
await this.sourceElement.page.mouse.up();
}
/** @inheritdoc */
async getValue() {
return (new element_1.O3rElement({
element: await this.getInputElement(),
page: this.sourceElement.page
})).getValue();
}
}
exports.O3rSliderElement = O3rSliderElement;
//# sourceMappingURL=slider-element.js.map