Skip to content

Commit 97c79a4

Browse files
committed
add .explore() and pretty print for python result types
1 parent 8781d6b commit 97c79a4

File tree

14 files changed

+586
-116
lines changed

14 files changed

+586
-116
lines changed

bindings/nodejs/index.d.ts

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export interface CommandOutput {
2323
stdout: string
2424
stderr: string
2525
}
26-
/** Result of a screenshot operation */
2726
export interface ScreenshotResult {
2827
width: number
2928
height: number
@@ -38,6 +37,22 @@ export interface UIElementAttributes {
3837
properties: Record<string, string | undefined | null>
3938
isKeyboardFocusable?: boolean
4039
}
40+
export interface ExploredElementDetail {
41+
role: string
42+
name?: string
43+
id?: string
44+
bounds?: Bounds
45+
value?: string
46+
description?: string
47+
text?: string
48+
parentId?: string
49+
childrenIds: Array<string>
50+
suggestedSelector: string
51+
}
52+
export interface ExploreResponse {
53+
parent: Element
54+
children: Array<ExploredElementDetail>
55+
}
4156
/** Main entry point for desktop automation. */
4257
export declare class Desktop {
4358
/**
@@ -96,50 +111,50 @@ export declare class Desktop {
96111
*/
97112
activateApplication(name: string): void
98113
/**
99-
* Capture a screenshot of the primary monitor.
114+
* (async) Capture a screenshot of the primary monitor.
100115
*
101116
* @returns {Promise<ScreenshotResult>} The screenshot data.
102117
*/
103118
captureScreen(): Promise<ScreenshotResult>
104119
/**
105-
* Run a shell command.
120+
* (async) Run a shell command.
106121
*
107122
* @param {string} [windowsCommand] - Command to run on Windows.
108123
* @param {string} [unixCommand] - Command to run on Unix.
109124
* @returns {Promise<CommandOutput>} The command output.
110125
*/
111126
runCommand(windowsCommand?: string | undefined | null, unixCommand?: string | undefined | null): Promise<CommandOutput>
112127
/**
113-
* Capture a screenshot of a specific monitor.
128+
* (async) Capture a screenshot of a specific monitor.
114129
*
115130
* @param {string} name - The name of the monitor to capture.
116131
* @returns {Promise<ScreenshotResult>} The screenshot data.
117132
*/
118133
captureMonitorByName(name: string): Promise<ScreenshotResult>
119134
/**
120-
* Perform OCR on an image file.
135+
* (async) Perform OCR on an image file.
121136
*
122137
* @param {string} imagePath - Path to the image file.
123138
* @returns {Promise<string>} The extracted text.
124139
*/
125140
ocrImagePath(imagePath: string): Promise<string>
126141
/**
127-
* Perform OCR on a screenshot.
142+
* (async) Perform OCR on a screenshot.
128143
*
129144
* @param {ScreenshotResult} screenshot - The screenshot to process.
130145
* @returns {Promise<string>} The extracted text.
131146
*/
132147
ocrScreenshot(screenshot: ScreenshotResult): Promise<string>
133148
/**
134-
* Find a window by criteria.
149+
* (async) Find a window by criteria.
135150
*
136151
* @param {string} [titleContains] - Text that should be in the window title.
137152
* @param {number} [timeoutMs] - Timeout in milliseconds.
138153
* @returns {Promise<Element>} The found window element.
139154
*/
140155
findWindowByCriteria(titleContains?: string | undefined | null, timeoutMs?: number | undefined | null): Promise<Element>
141156
/**
142-
* Get the currently focused browser window.
157+
* (async) Get the currently focused browser window.
143158
*
144159
* @returns {Promise<Element>} The current browser window element.
145160
*/
@@ -152,13 +167,13 @@ export declare class Desktop {
152167
*/
153168
locator(selector: string): Locator
154169
/**
155-
* Get the currently focused window.
170+
* (async) Get the currently focused window.
156171
*
157172
* @returns {Promise<Element>} The current window element.
158173
*/
159174
getCurrentWindow(): Promise<Element>
160175
/**
161-
* Get the currently focused application.
176+
* (async) Get the currently focused application.
162177
*
163178
* @returns {Promise<Element>} The current application element.
164179
*/
@@ -360,25 +375,31 @@ export declare class Element {
360375
* @returns {Element | null} The containing window element, if available.
361376
*/
362377
window(): Element | null
378+
/**
379+
* Explore this element and its direct children.
380+
*
381+
* @returns {ExploreResponse} Details about the element and its children.
382+
*/
383+
explore(): ExploreResponse
363384
}
364385
/** Locator for finding UI elements by selector. */
365386
export declare class Locator {
366387
/**
367-
* Get the first matching element.
388+
* (async) Get the first matching element.
368389
*
369390
* @returns {Promise<Element>} The first matching element.
370391
*/
371392
first(): Promise<Element>
372393
/**
373-
* Get all matching elements.
394+
* (async) Get all matching elements.
374395
*
375396
* @param {number} [timeoutMs] - Timeout in milliseconds.
376397
* @param {number} [depth] - Maximum depth to search.
377398
* @returns {Promise<Array<Element>>} List of matching elements.
378399
*/
379400
all(timeoutMs?: number | undefined | null, depth?: number | undefined | null): Promise<Array<Element>>
380401
/**
381-
* Wait for the first matching element.
402+
* (async) Wait for the first matching element.
382403
*
383404
* @param {number} [timeoutMs] - Timeout in milliseconds.
384405
* @returns {Promise<Element>} The first matching element.
@@ -406,14 +427,14 @@ export declare class Locator {
406427
*/
407428
locator(selector: string): Locator
408429
/**
409-
* Click on the first matching element.
430+
* (async) Click on the first matching element.
410431
*
411432
* @param {number} [timeoutMs] - Timeout in milliseconds.
412433
* @returns {Promise<ClickResult>} Result of the click operation.
413434
*/
414435
click(timeoutMs?: number | undefined | null): Promise<ClickResult>
415436
/**
416-
* Type text into the first matching element.
437+
* (async) Type text into the first matching element.
417438
*
418439
* @param {string} text - The text to type.
419440
* @param {boolean} [useClipboard] - Whether to use clipboard for pasting.
@@ -422,58 +443,58 @@ export declare class Locator {
422443
*/
423444
typeText(text: string, useClipboard?: boolean | undefined | null, timeoutMs?: number | undefined | null): Promise<void>
424445
/**
425-
* Press a key on the first matching element.
446+
* (async) Press a key on the first matching element.
426447
*
427448
* @param {string} key - The key to press.
428449
* @param {number} [timeoutMs] - Timeout in milliseconds.
429450
* @returns {Promise<void>}
430451
*/
431452
pressKey(key: string, timeoutMs?: number | undefined | null): Promise<void>
432453
/**
433-
* Get text from the first matching element.
454+
* (async) Get text from the first matching element.
434455
*
435456
* @param {number} [maxDepth] - Maximum depth to search for text.
436457
* @param {number} [timeoutMs] - Timeout in milliseconds.
437458
* @returns {Promise<string>} The element's text content.
438459
*/
439460
text(maxDepth?: number | undefined | null, timeoutMs?: number | undefined | null): Promise<string>
440461
/**
441-
* Get attributes from the first matching element.
462+
* (async) Get attributes from the first matching element.
442463
*
443464
* @param {number} [timeoutMs] - Timeout in milliseconds.
444465
* @returns {Promise<UIElementAttributes>} The element's attributes.
445466
*/
446467
attributes(timeoutMs?: number | undefined | null): Promise<UIElementAttributes>
447468
/**
448-
* Get bounds from the first matching element.
469+
* (async) Get bounds from the first matching element.
449470
*
450471
* @param {number} [timeoutMs] - Timeout in milliseconds.
451472
* @returns {Promise<Bounds>} The element's bounds.
452473
*/
453474
bounds(timeoutMs?: number | undefined | null): Promise<Bounds>
454475
/**
455-
* Check if the element is visible.
476+
* (async) Check if the element is visible.
456477
*
457478
* @param {number} [timeoutMs] - Timeout in milliseconds.
458479
* @returns {Promise<boolean>} True if the element is visible.
459480
*/
460481
isVisible(timeoutMs?: number | undefined | null): Promise<boolean>
461482
/**
462-
* Wait for the element to be enabled.
483+
* (async) Wait for the element to be enabled.
463484
*
464485
* @param {number} [timeoutMs] - Timeout in milliseconds.
465486
* @returns {Promise<Element>} The enabled element.
466487
*/
467488
expectEnabled(timeoutMs?: number | undefined | null): Promise<Element>
468489
/**
469-
* Wait for the element to be visible.
490+
* (async) Wait for the element to be visible.
470491
*
471492
* @param {number} [timeoutMs] - Timeout in milliseconds.
472493
* @returns {Promise<Element>} The visible element.
473494
*/
474495
expectVisible(timeoutMs?: number | undefined | null): Promise<Element>
475496
/**
476-
* Wait for the element's text to equal the expected text.
497+
* (async) Wait for the element's text to equal the expected text.
477498
*
478499
* @param {string} expectedText - The expected text.
479500
* @param {number} [maxDepth] - Maximum depth to search for text.
@@ -482,26 +503,33 @@ export declare class Locator {
482503
*/
483504
expectTextEquals(expectedText: string, maxDepth?: number | undefined | null, timeoutMs?: number | undefined | null): Promise<Element>
484505
/**
485-
* Double click on the first matching element.
506+
* (async) Double click on the first matching element.
486507
*
487508
* @param {number} [timeoutMs] - Timeout in milliseconds.
488509
* @returns {Promise<ClickResult>} Result of the click operation.
489510
*/
490511
doubleClick(timeoutMs?: number | undefined | null): Promise<ClickResult>
491512
/**
492-
* Right click on the first matching element.
513+
* (async) Right click on the first matching element.
493514
*
494515
* @param {number} [timeoutMs] - Timeout in milliseconds.
495516
* @returns {Promise<void>}
496517
*/
497518
rightClick(timeoutMs?: number | undefined | null): Promise<void>
498519
/**
499-
* Hover over the first matching element.
520+
* (async) Hover over the first matching element.
500521
*
501522
* @param {number} [timeoutMs] - Timeout in milliseconds.
502523
* @returns {Promise<void>}
503524
*/
504525
hover(timeoutMs?: number | undefined | null): Promise<void>
526+
/**
527+
* (async) Explore the first matching element and its direct children.
528+
*
529+
* @param {number} [timeoutMs] - Timeout in milliseconds.
530+
* @returns {Promise<ExploreResponse>} Details about the element and its children.
531+
*/
532+
explore(timeoutMs?: number | undefined | null): Promise<ExploreResponse>
505533
}
506534
/** Thrown when an element is not found. */
507535
export declare class ElementNotFoundError {

bindings/nodejs/src/desktop.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Desktop {
113113
.map_err(map_error)
114114
}
115115

116-
/// Capture a screenshot of the primary monitor.
116+
/// (async) Capture a screenshot of the primary monitor.
117117
///
118118
/// @returns {Promise<ScreenshotResult>} The screenshot data.
119119
#[napi]
@@ -127,7 +127,7 @@ impl Desktop {
127127
.map_err(map_error)
128128
}
129129

130-
/// Run a shell command.
130+
/// (async) Run a shell command.
131131
///
132132
/// @param {string} [windowsCommand] - Command to run on Windows.
133133
/// @param {string} [unixCommand] - Command to run on Unix.
@@ -143,7 +143,7 @@ impl Desktop {
143143
.map_err(map_error)
144144
}
145145

146-
/// Capture a screenshot of a specific monitor.
146+
/// (async) Capture a screenshot of a specific monitor.
147147
///
148148
/// @param {string} name - The name of the monitor to capture.
149149
/// @returns {Promise<ScreenshotResult>} The screenshot data.
@@ -158,7 +158,7 @@ impl Desktop {
158158
.map_err(map_error)
159159
}
160160

161-
/// Perform OCR on an image file.
161+
/// (async) Perform OCR on an image file.
162162
///
163163
/// @param {string} imagePath - Path to the image file.
164164
/// @returns {Promise<string>} The extracted text.
@@ -168,7 +168,7 @@ impl Desktop {
168168
.map_err(map_error)
169169
}
170170

171-
/// Perform OCR on a screenshot.
171+
/// (async) Perform OCR on a screenshot.
172172
///
173173
/// @param {ScreenshotResult} screenshot - The screenshot to process.
174174
/// @returns {Promise<string>} The extracted text.
@@ -183,7 +183,7 @@ impl Desktop {
183183
.map_err(map_error)
184184
}
185185

186-
/// Find a window by criteria.
186+
/// (async) Find a window by criteria.
187187
///
188188
/// @param {string} [titleContains] - Text that should be in the window title.
189189
/// @param {number} [timeoutMs] - Timeout in milliseconds.
@@ -197,7 +197,7 @@ impl Desktop {
197197
.map_err(map_error)
198198
}
199199

200-
/// Get the currently focused browser window.
200+
/// (async) Get the currently focused browser window.
201201
///
202202
/// @returns {Promise<Element>} The current browser window element.
203203
#[napi]
@@ -218,7 +218,7 @@ impl Desktop {
218218
Ok(Locator::from(loc))
219219
}
220220

221-
/// Get the currently focused window.
221+
/// (async) Get the currently focused window.
222222
///
223223
/// @returns {Promise<Element>} The current window element.
224224
#[napi]
@@ -228,7 +228,7 @@ impl Desktop {
228228
.map_err(map_error)
229229
}
230230

231-
/// Get the currently focused application.
231+
/// (async) Get the currently focused application.
232232
///
233233
/// @returns {Promise<Element>} The current application element.
234234
#[napi]

0 commit comments

Comments
 (0)