import { $, $$ } from '@wdio/globals'; import { dictionary } from './index.js'; type SelectorNode = string | Record; export function getSelector(route: string): string { const value = route.split('.').reduce((current, segment) => { if (!current || typeof current !== 'object') return undefined; return (current as Record)[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> { 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> { const selector = getSelector(route); const firstElement = $(selector); await firstElement.waitForExist({ timeout: 60_000 }); await firstElement.waitForDisplayed({ timeout: 60_000 }); return $$(selector); } export type { SelectorNode };