Files
TS-CUCUMBER-WDIO-QK/test/selectors/actionHelper.ts
isopropilick 896c3a121a
Some checks failed
CI / validate (push) Has been cancelled
ok
2026-08-27 15:00:50 -06:00

38 lines
1.3 KiB
TypeScript

import { $, $$ } from '@wdio/globals';
import { dictionary } from './index.js';
type SelectorNode = string | Record<string, unknown>;
export function getSelector(route: string): string {
const value = route.split('.').reduce<unknown>((current, segment) => {
if (!current || typeof current !== 'object') return undefined;
return (current as Record<string, unknown>)[segment];
}, dictionary);
if (typeof value !== 'string' || value.trim() === '') {
throw new Error(`Selector route "${route}" does not resolve to a selector string.`);
}
return value;
}
export async function getElement(route: string, shouldBeVisible = true): Promise<ReturnType<typeof $>> {
const element = $(getSelector(route));
if (shouldBeVisible) {
await element.waitForExist({ timeout: 60_000 });
await element.waitForDisplayed({ timeout: 60_000 });
} else {
await element.waitForDisplayed({ timeout: 60_000, reverse: true });
}
return element;
}
export async function getElements(route: string): Promise<ReturnType<typeof $$>> {
const selector = getSelector(route);
const firstElement = $(selector);
await firstElement.waitForExist({ timeout: 60_000 });
await firstElement.waitForDisplayed({ timeout: 60_000 });
return $$(selector);
}
export type { SelectorNode };