@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
62 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatSelect = void 0;
const element_1 = require("../element");
/**
* Implementation dedicated to Playwright.
*/
class MatSelect extends element_1.O3rElement {
constructor(sourceElement) {
super(sourceElement);
}
/** @inheritdoc */
async selectByIndex(index, timeout = 5000) {
await this.click();
const options = this.sourceElement.page.locator('mat-option');
await options.first().waitFor({ state: 'attached', timeout });
if ((await options.count()) >= index + 1) {
const selectedOption = { element: options.nth(index), page: this.sourceElement.page };
const option = new element_1.O3rElement(selectedOption);
return option.click();
}
else {
return Promise.reject(new Error(`Option with index ${index} not found in select element.`));
}
}
/** @inheritdoc */
async selectByValue(value, timeout = 5000) {
await this.click();
const options = this.sourceElement.page.locator('mat-option');
await options.first().waitFor({ state: 'attached', timeout });
const optionsCount = await options.count();
for (let i = 0; i < optionsCount; i++) {
const selectedOption = { element: options.nth(i), page: this.sourceElement.page };
const option = new element_1.O3rElement(selectedOption);
if (await option.getAttribute('ng-reflect-value') === value) {
return option.click();
}
}
return Promise.reject(new Error(`Option with value ${value} not found in select element.`));
}
/** @inheritdoc */
async selectByLabel(label, timeout = 5000) {
await this.click();
const options = this.sourceElement.page.locator('mat-option');
await options.first().waitFor({ state: 'attached', timeout });
const optionsCount = await options.count();
for (let i = 0; i < optionsCount; i++) {
const selectedOption = { element: options.nth(i), page: this.sourceElement.page };
const option = new element_1.O3rElement(selectedOption);
if (await option.getText() === label) {
return option.click();
}
}
return Promise.reject(new Error(`Option with label ${label} not found in select element.`));
}
/** @inheritDoc */
getValue() {
throw new Error('Cannot use "getValue" function on a Material Select element. Use "getPlainText()" instead.');
}
}
exports.MatSelect = MatSelect;
//# sourceMappingURL=select-material.js.map