systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
55 lines (54 loc) • 1.85 kB
JavaScript
import { Widget } from './widget.js';
export class ComboBox extends Widget {
async click() {
return this.elem.byCSS('.dropdown-toggle').click();
}
async isOptionsListOpen() {
return await this.byCSS('.ag-root-wrapper').isPresent();
}
async openOptionsList() {
const isOpen = await this.isOptionsListOpen();
if (!isOpen) {
await this.click();
await this.waitUntil(async () => this.isOptionsListOpen());
}
}
async closeOptionsList() {
const isOpen = await this.isOptionsListOpen();
if (isOpen) {
await this.click();
await this.waitUntil(async () => !(await this.isOptionsListOpen()));
}
}
async getOptions() {
await this.openOptionsList();
let content = [];
let rows = this.allByCSS('.ag-cell-value');
let numberOfItems = await rows.count();
for (let i = 0; i < numberOfItems; i++) {
let text = await rows.get(i).getText();
content.push(text);
}
await this.closeOptionsList();
return content;
}
async selectOptionByText(text) {
await this.openOptionsList();
let rows = this.allByCSS('.ag-cell-value');
let numberOfItems = await rows.count();
for (let i = 0; i < numberOfItems; i++) {
let optionText = await rows.get(i).getHTML(false);
if (text === optionText) {
await this.getOptionSelector(i).click();
return;
}
}
}
async selectOptionByNumber(optionIndex) {
await this.openOptionsList();
await this.getOptionSelector(optionIndex).click();
}
getOptionSelector(optionIndex) {
return this.allByCSS(`[role='row'][row-index='` + optionIndex + `']`).get(0);
}
}