Wait for a window?

Jan 17, 2013 at 11:40 PM

OK,  this is probably something really basic I am missing, but, how do I wait for a window to open? I have start-process which opens a file. I want to wait for that file to load. I tried '-IsCritical' but my script seems to blow past that and fail:

Get-UIAWindow -Name 'Test File Window Name' -IsCritical

 

Thanks!

Jan 18, 2013 at 12:05 AM
Edited Jan 18, 2013 at 12:32 AM
peakbagger wrote:

OK,  this is probably something really basic I am missing, but, how do I wait for a window to open? I have start-process which opens a file. I want to wait for that file to load. I tried '-IsCritical' but my script seems to blow past that and fail:

Get-UIAWindow -Name 'Test File Window Name' -IsCritical

 

Thanks!

Scratch that. That is not the issue. What happens is that it is failing on a 'Get-UIACustom'. Which is odd, because it works on my Windows 7 machine but fails on a Windows 2008 R2 server. Any ideas why this would be so? Same application running on both.  

The error is:

Get-UIACustom : Get-UIACustom: timeout expired for class: ' + , control type: Custom, title: DisplayAt C:\scripts\openMDE3.ps1:12 char:14+ Get-UIACustom <<<<  -Name 'Display' | `    + CategoryInfo          : OperationTimeout: (:) [Get-UIACustom], Exception    + FullyQualifiedErrorId : ControlIsNull,UIAutomation.Commands.GetUIACustomCommand

 

UIAutomationSpy shows a Get-UIACustom -Name 'Display' 

Coordinator
Jan 18, 2013 at 6:38 AM

Hi peakbagger,

I'll provide more explanation later today.

Shortly, the -IsCritical parameter is for managing test results only |make your test results RED).

By default, the Get-UIAWindow cmdlet uses the default timeout [UIAutomation.Preferences]::Timeout  (by default, it equalts to 5000 milliseconds).

Cmdlet searches for a window and, if succeed, returns it in 5 or less seconds. You can provide a custom value for a single run:

Start-Process calc -PassThru | Get-UIAWindow -Seconds 1

Get-UIA[ControlType] cmdlets also support timeouts.

 

Sometimes, the schema (Start-Process app -PassThru | Get-UIAWindow) does not work, for example if a system is 64-bit and an app is 32-bit (an mmc snapin is a typical example).

 

It would be nice, if you put a screenshot somewhere (you should have in yout %TEMP% folder. Screenshots are saved, by default, on fail) or to run a spot instance at Amazon with your app? Now, I don't understand what the problemous control is.

 

 

Coordinator
Jan 18, 2013 at 11:43 PM

I re-read your posts. If a window is too slow on start, I'd recommend to increase timeout (the -Timeout parameter is in milliseconds (as requires Cmdlet Design Guidelines), its brother -Seconds in seconds):

Start-Process calc -PassThru | Get-UIAWindow -Seconds 30;
# or
Start-Process calc; Get-UIAWindow -pn calc -Seconds 30;

Regarding the ControlType.Custom control, I'd recommend the following sequence of actions:

1. use UIAutomationSpy on both hosts to recognize the control (if a control persists on both OSes and o the same type, and has the same name, go to step 2)

2. maybe, your host is slow or the app has a number of controls

2.1 you can increase the timeout

| Get-UIACustom -Name DisplayAt -Seconds 20;

2.2 you can learn if it has handle (by using UIAutomationSpy (tab Properties), UIA Verify or code like

Get-UIACustom -Name DisplayAt | Read-UIAControlNativeWindowHandle;

Often, the following instruction:

Get-UIACustom -Name DisplayAt -Win32;
accelerates execution (search for handle is faster that regular MS UI Automation). However, it won't work if a control's title does not match the Name of a control.

 

 

 

Jan 19, 2013 at 4:28 AM

Ahhh..yes, thanks let my try the timeout and see how that works. Thanks very much for the pointers - it is much appreciated. I'm fairly clueless!