Skip to content

Commit

Permalink
Better command types
Browse files Browse the repository at this point in the history
  • Loading branch information
vbfox committed Aug 6, 2024
1 parent baddad5 commit 9eafcc5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
);

Expand Down
26 changes: 21 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -105,20 +106,20 @@ export type WaldoBrowser = {
resetApp(): Promise<void>;
tapElement(
property: string,
value: any,
value: string,
timeout?: number,
delay?: number,
waitForStability?: boolean,
): Promise<void>;
tapElementWith(
predicate: (n: any) => boolean,
predicate: (n: WaldoTreeElement) => boolean,
position?: number | 'first' | 'last',
retries?: number,
delay?: number,
): Promise<void>;
typeInElement(
property: string,
value: any,
value: string,
text: string,
timeout?: number,
delay?: number,
Expand All @@ -133,7 +134,7 @@ export type WaldoBrowser = {
tap(x: number, y: number): Promise<void>;
waitForElement(
property: string,
value: any,
value: string,
timeout?: number,
delay?: number,
waitForStability?: boolean,
Expand All @@ -143,7 +144,22 @@ export type WaldoBrowser = {
* Simulate a 'tap' gesture at the center of the given bounding box.
*/
tapCenterOfBox(box: BoundingBox): Promise<void>;
getNodes(predicate: (n: any) => boolean): Promise<any[]>;

/**
* 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<WaldoTreeElement[]>;

/**
* 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<WaldoTree>;

/**
* Simulate a 'swipe' gesture in the given direction.
Expand Down

0 comments on commit 9eafcc5

Please sign in to comment.