diff --git a/src/commands.ts b/src/commands.ts index 144f0ad..08edb28 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -147,9 +147,9 @@ export function addDriverCommands(driver: WebdriverIO.Browser) { 'getNodes', async function commandFn( this: WebdriverIO.Browser, - predicate: (n: WaldoTreeElement) => boolean, + predicate?: (n: WaldoTreeElement) => boolean, ) { - return findInTree(this, predicate); + return findInTree(this, predicate ?? (() => true)); }, ); diff --git a/src/types.ts b/src/types.ts index 8cf8277..191ed9d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ import type { Capabilities } from '@wdio/types'; import type { ElementReference } from '@wdio/protocols'; +import { WaldoTree, WaldoTreeElement } from './tree-types.js'; export type WaldoEnvironment = 'production' | 'staging' | 'development'; @@ -105,20 +106,20 @@ export type WaldoBrowser = { resetApp(): Promise; tapElement( property: string, - value: any, + value: string, timeout?: number, delay?: number, waitForStability?: boolean, ): Promise; tapElementWith( - predicate: (n: any) => boolean, + predicate: (n: WaldoTreeElement) => boolean, position?: number | 'first' | 'last', retries?: number, delay?: number, ): Promise; typeInElement( property: string, - value: any, + value: string, text: string, timeout?: number, delay?: number, @@ -133,7 +134,7 @@ export type WaldoBrowser = { tap(x: number, y: number): Promise; waitForElement( property: string, - value: any, + value: string, timeout?: number, delay?: number, waitForStability?: boolean, @@ -143,7 +144,22 @@ export type WaldoBrowser = { * Simulate a 'tap' gesture at the center of the given bounding box. */ tapCenterOfBox(box: BoundingBox): Promise; - getNodes(predicate: (n: any) => boolean): Promise; + + /** + * Get all nodes in the Waldo tree that match the given predicate. + * + * **Note**: This command is only available when using the Waldo automation via the + * `'waldo:automationName': 'Waldo'` capability. + */ + getNodes(predicate?: (n: WaldoTreeElement) => boolean): Promise; + + /** + * Parse the current Waldo tree returned by `getPageSource()` and return it as a JSON object. + * + * **Note**: This command is only available when using the Waldo automation via the + * `'waldo:automationName': 'Waldo'` capability. + */ + getWaldoTree(): Promise; /** * Simulate a 'swipe' gesture in the given direction.