@@ -64,6 +64,24 @@ export async function getPageSource(this: NovaWindowsDriver): Promise<string> {
6464 return await this . sendPowerShellCommand ( GET_PAGE_SOURCE_COMMAND . format ( AutomationElement . automationRoot ) ) ;
6565}
6666
67+ export async function maximizeWindow ( this : NovaWindowsDriver ) : Promise < void > {
68+ const automationRoot = new FoundAutomationElement ( AutomationElement . automationRoot . buildGetPropertyCommand ( Property . RUNTIME_ID ) ) ;
69+ try {
70+ await this . sendPowerShellCommand ( automationRoot . buildMaximizeCommand ( ) ) ;
71+ } catch {
72+ throw new errors . UnknownError ( 'Failed to maximize the window.' ) ;
73+ }
74+ }
75+
76+ export async function minimizeWindow ( this : NovaWindowsDriver ) : Promise < void > {
77+ const automationRoot = new FoundAutomationElement ( AutomationElement . automationRoot . buildGetPropertyCommand ( Property . RUNTIME_ID ) ) ;
78+ try {
79+ await this . sendPowerShellCommand ( automationRoot . buildMinimizeCommand ( ) ) ;
80+ } catch {
81+ throw new errors . UnknownError ( 'Failed to minimize the window.' ) ;
82+ }
83+ }
84+
6785export async function getScreenshot ( this : NovaWindowsDriver ) : Promise < string > {
6886 const automationRootId = await this . sendPowerShellCommand ( AutomationElement . automationRoot . buildCommand ( ) ) ;
6987
@@ -287,10 +305,17 @@ export async function waitForNewWindow(this: NovaWindowsDriver, pid: number, tim
287305 let attempts = 0 ;
288306
289307 while ( Date . now ( ) - start < timeout ) {
290- const handles = getWindowAllHandlesForProcessIds ( [ pid ] ) ;
308+ // const handles = getWindowAllHandlesForProcessIds([pid]);
309+
310+ // if (handles.length > 0) {
311+ // return handles[handles.length - 1];
312+ // }
291313
292- if ( handles . length > 0 ) {
293- return handles [ handles . length - 1 ] ;
314+ const elements = await this . sendPowerShellCommand ( AutomationElement . rootElement . findAll ( TreeScope . CHILDREN , new PropertyCondition ( Property . PROCESS_ID , new PSInt32 ( pid ) ) ) . buildCommand ( ) ) ;
315+ const elementIds = elements . split ( '\n' ) . map ( ( id ) => id . trim ( ) ) . filter ( Boolean ) ;
316+ if ( elementIds . length > 0 ) {
317+ const nativeWindowHandle = await this . sendPowerShellCommand ( new FoundAutomationElement ( elementIds [ 0 ] ) . buildGetPropertyCommand ( Property . NATIVE_WINDOW_HANDLE ) ) ;
318+ return Number ( nativeWindowHandle ) ;
294319 }
295320
296321 this . log . debug ( `Waiting for the process window to appear... (${ ++ attempts } /${ Math . floor ( timeout / SLEEP_INTERVAL_MS ) } )` ) ;
0 commit comments