Why does it take so long for CUIT to recognize a window no longer exists?
-
Thursday, June 03, 2010 10:40 PM
After I start my application, I'm waiting for the splash screen to appear and then disappear before continuing. Here's how I do that:
public static void WaitForSwitcherProMainWindow(UIMap map) { Debug.WriteLine("**************************************"); Debug.WriteLine("Waiting for splash screen open"); Debug.WriteLine("**************************************"); // Wait for splash screen to appear UITestControl.WaitForCondition<UITestControl>(map.UISwitcherProDesktopSpWindow, SwitcherPro.DoesWindowExist); Debug.WriteLine("**************************************"); Debug.WriteLine("Waiting for splash screen close"); Debug.WriteLine("**************************************"); // Wait for splash screen to disappear UITestControl.WaitForCondition<UITestControl>(map.UISwitcherProDesktopSpWindow, SwitcherPro.DoesWindowNotExist); Debug.WriteLine("**************************************"); Debug.WriteLine("Done waiting for splash screen"); Debug.WriteLine("**************************************"); } public static bool DoesWindowExist(UITestControl control) { WinWindow window = control as WinWindow; //return migrateDialog.Exists || doneText.Exists; WaitForReadyLevel cachedValue = Playback.PlaybackSettings.WaitForReadyLevel; Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled; try { //if (TryFind(window)) if (window.Exists) { return true; } } finally { Playback.PlaybackSettings.WaitForReadyLevel = cachedValue; } return false; } public static bool DoesWindowNotExist(UITestControl control) { WinWindow window = control as WinWindow; //return migrateDialog.Exists || doneText.Exists; WaitForReadyLevel cachedValue = Playback.PlaybackSettings.WaitForReadyLevel; Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled; try { //if (!TryFind(window)) if (!window.Exists) { return true; } } finally { Playback.PlaybackSettings.WaitForReadyLevel = cachedValue; } return false; }Watching the output as my application runs, the splash screen disappears and then about 53 seconds later I see the "Done waiting for splash screen".
Any reason this doesn't react faster than that? Like within a few seconds?
I have the debug output but its too big to post here.
All Replies
-
Friday, June 04, 2010 1:55 AM
The delay ie because it is trying to search for the control (window) which no longer exists. There is a default search timeout, which you can reduce it by setting the Playback.PlaybackSettings.SearchTimeout, but use it wisely since it might affect playback scenarios.- Proposed As Answer by Tapas [MSFT]Microsoft Employee Friday, June 04, 2010 1:56 AM
- Unproposed As Answer by Brandon Hoppe Friday, June 04, 2010 3:09 PM
- Marked As Answer by Brandon Hoppe Friday, June 04, 2010 3:46 PM
-
Friday, June 04, 2010 2:44 PM
Tapas,
I tried lowering the timeout to see how it affected it like so:
public static bool DoesWindowNotExist(UITestControl control) { WinWindow window = control as WinWindow; //return migrateDialog.Exists || doneText.Exists; WaitForReadyLevel cachedValue = Playback.PlaybackSettings.WaitForReadyLevel; Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled; int cachedTimeout = Playback.PlaybackSettings.SearchTimeout; Playback.PlaybackSettings.SearchTimeout = 2000; try { //if (!TryFind(window)) if (!window.Exists) { Debug.WriteLine("**************************************"); Debug.WriteLine("Windows does not exist"); Debug.WriteLine("**************************************"); return true; } Debug.WriteLine("**************************************"); Debug.WriteLine("Window exists"); Debug.WriteLine("**************************************"); } finally { Playback.PlaybackSettings.WaitForReadyLevel = cachedValue; Playback.PlaybackSettings.SearchTimeout = cachedTimeout; } return false; }I set the timeout 2 seconds. Watching the debug output, I does react quicker to the window disappearing, but then it looks like it picks up a different window and keeps tracking that instead.
************************************** Window exists ************************************** I, 10928, 13, 2010/06/04, 09:38:33.441, 6972761348156, QTAgent32.exe, Playback - < Robustness level was set to '1' > V, 10928, 13, 2010/06/04, 09:38:33.442, 6972761349925, QTAgent32.exe, AL: Setting search timeout to 120000 ms I, 10928, 13, 2010/06/04, 09:38:33.543, 6972761611751, QTAgent32.exe, Playback - < Robustness level was set to '0' > V, 10928, 13, 2010/06/04, 09:38:33.544, 6972761615493, QTAgent32.exe, AL: Setting search timeout to 2000 ms V, 10928, 13, 2010/06/04, 09:38:33.545, 6972761617530, QTAgent32.exe, AL : GetProperty, propertyName: Exists V, 10928, 13, 2010/06/04, 09:38:33.546, 6972761619644, QTAgent32.exe, AL : EnsureValid() V, 10928, 13, 2010/06/04, 09:38:33.546, 6972761621305, QTAgent32.exe, AL : UITestControl.WaitForControlReady - 60000 ************************************** Window exists ************************************** I, 10928, 13, 2010/06/04, 09:38:33.559, 6972761653292, QTAgent32.exe, Playback - < Robustness level was set to '1' > V, 10928, 13, 2010/06/04, 09:38:33.559, 6972761655090, QTAgent32.exe, AL: Setting search timeout to 120000 ms I, 10928, 13, 2010/06/04, 09:38:33.660, 6972761916749, QTAgent32.exe, Playback - < Robustness level was set to '0' > V, 10928, 13, 2010/06/04, 09:38:33.661, 6972761920145, QTAgent32.exe, AL: Setting search timeout to 2000 ms V, 10928, 13, 2010/06/04, 09:38:33.662, 6972761923613, QTAgent32.exe, AL : GetProperty, propertyName: Exists V, 10928, 13, 2010/06/04, 09:38:33.665, 6972761930268, QTAgent32.exe, AL : EnsureValid() V, 10928, 13, 2010/06/04, 09:38:33.669, 6972761940186, QTAgent32.exe, AL : UITestControl.WaitForControlReady - 60000 I, 10928, 13, 2010/06/04, 09:38:33.669, 6972761942000, QTAgent32.exe, AL : Refetching the UITestControl with Qid = ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' I, 10928, 13, 2010/06/04, 09:38:33.670, 6972761943666, QTAgent32.exe, ManagedWrapper : FindFromPartialQueryId with QID:;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' I, 10928, 13, 2010/06/04, 09:38:33.671, 6972761945437, QTAgent32.exe, ManagedWrapper : ResetSkipStep() V, 10928, 13, 2010/06/04, 09:38:33.672, 6972761947628, QTAgent32.exe, FindTopLevelWindowHelper - Pass 1 - SearchInMinWindows, SmartMatch flags set to false and SearchRetryCount 1 V, 10928, 13, 2010/06/04, 09:38:33.673, 6972761950619, QTAgent32.exe, QueryId : Creating QueryId from: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 13, 2010/06/04, 09:38:33.674, 6972761952510, QTAgent32.exe, QueryId : Creating SingleQueryId from: [VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' W, 10928, 13, 2010/06/04, 09:38:35.835, 6972767580020, QTAgent32.exe, Playback - [WARNING] Internal warning: Window Not Found: [VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 13, 2010/06/04, 09:38:35.836, 6972767582637, QTAgent32.exe, Playback - 6.4.2010 @9:38:35 E, 10928, 13, 2010/06/04, 09:38:35.837, 6972767584837, QTAgent32.exe, <a class=failure>Playback - {1} [FAILED] Function ElementFetcher::FindScreenElement failed to locate UI element (Searching: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window') (The object specified was not found.) E, 10928, 13, 2010/06/04, 09:38:36.097, 6972768261619, QTAgent32.exe, Playback - [IMAGE] C:\Users\a0212204.ENT\AppData\Local\Temp\UITestLogs\LastRun\RPF9A61.png W, 10928, 13, 2010/06/04, 09:38:36.098, 6972768264491, QTAgent32.exe, Playback - [WARNING] Internal warning: Couldn't find descendants that match QueryId W, 10928, 13, 2010/06/04, 09:38:36.113, 6972768302691, QTAgent32.exe, PERF WARNING: FindTopLevelWindowHelper::FindAllDescendents: took 2439 ms. Expected it to take maximum 500 ms. V, 10928, 13, 2010/06/04, 09:38:36.116, 6972768310841, QTAgent32.exe, FindTopLevelWindowHelper - Got exception in pass 0, ignoring it System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IRPFPlayback.FindAllScreenElements(IScreenElement pScreenElementStart, String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth, Object[]& foundDescendants) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindTopLevelWindowHelper(String queryId) V, 10928, 13, 2010/06/04, 09:38:36.117, 6972768313424, QTAgent32.exe, FindTopLevelWindowHelper - Pass 2 - SearchInMinWindows, SmartMatch is false, SearchTimeOut set to 300 ms V, 10928, 13, 2010/06/04, 09:38:36.118, 6972768315628, QTAgent32.exe, QueryId : Creating QueryId from: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 13, 2010/06/04, 09:38:36.118, 6972768317627, QTAgent32.exe, QueryId : Creating SingleQueryId from: [VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 10, 2010/06/04, 09:38:36.406, DTA0212204\QTAgent32.exe, AgentObject: Sending heartbeat to listeners V, 10928, 10, 2010/06/04, 09:38:36.407, DTA0212204\QTAgent32.exe, AgentObject: Returned from sending heartbeat W, 10928, 13, 2010/06/04, 09:38:36.603, 6972769579394, QTAgent32.exe, Playback - [WARNING] Internal warning: Window Not Found: [VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 13, 2010/06/04, 09:38:36.604, 6972769582014, QTAgent32.exe, Playback - 6.4.2010 @9:38:36 E, 10928, 13, 2010/06/04, 09:38:36.605, 6972769583931, QTAgent32.exe, <a class=failure>Playback - {2} [FAILED] Function ElementFetcher::FindScreenElement failed to locate UI element (Searching: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window') (The object specified was not found.) E, 10928, 13, 2010/06/04, 09:38:36.857, 6972770242264, QTAgent32.exe, Playback - [IMAGE] C:\Users\a0212204.ENT\AppData\Local\Temp\UITestLogs\LastRun\RPF9D5F.png W, 10928, 13, 2010/06/04, 09:38:36.859, 6972770244954, QTAgent32.exe, Playback - [WARNING] Internal warning: Couldn't find descendants that match QueryId W, 10928, 13, 2010/06/04, 09:38:36.869, 6972770272975, QTAgent32.exe, PERF WARNING: FindTopLevelWindowHelper::FindAllDescendents: took 751 ms. Expected it to take maximum 500 ms. V, 10928, 13, 2010/06/04, 09:38:36.870, 6972770275195, QTAgent32.exe, FindTopLevelWindowHelper - Got exception in pass 1, ignoring it System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IRPFPlayback.FindAllScreenElements(IScreenElement pScreenElementStart, String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth, Object[]& foundDescendants) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindTopLevelWindowHelper(String queryId) V, 10928, 13, 2010/06/04, 09:38:36.871, 6972770277048, QTAgent32.exe, FindTopLevelWindowHelper - Pass 3 - SearchInMinWindows, SmartMatch is true, SearchTimeOut set to 3000 ms V, 10928, 13, 2010/06/04, 09:38:36.871, 6972770278696, QTAgent32.exe, QueryId : Creating QueryId from: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 13, 2010/06/04, 09:38:36.872, 6972770280395, QTAgent32.exe, QueryId : Creating SingleQueryId from: [VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' V, 10928, 13, 2010/06/04, 09:38:37.518, 6972771963200, QTAgent32.exe, Playback - SmartMatch started with : Class = 'WindowsForms10.Window', Target = 'SwitcherPro Desktop Splash Screen', Target-left = 'SwitcherPro Desktop Splash Screen', Target-right = '' V, 10928, 13, 2010/06/04, 09:38:37.520, 6972771967338, QTAgent32.exe, Playback - SmartMatch: Window added : 6b19e6 'SwitcherPro Desktop - TPS54362EVM 28V to 5V @ 2.5A - 1163' 40 V, 10928, 13, 2010/06/04, 09:38:37.521, 6972771969840, QTAgent32.exe, Playback - SmartMatched returned: 6b19e6 SwitcherPro Desktop - TPS54362EVM 28V to 5V @ 2.5A - 1163 40 W, 10928, 13, 2010/06/04, 09:38:38.906, 6972775577059, QTAgent32.exe, Playback - [WARNING] Internal warning: Window with Class "WindowsForms10.Window" and Title "SwitcherPro Desktop Splash Screen" was not found, so similar window with Class "WindowsForms10.Window.8.app.0.33c0d9d" and Title "SwitcherPro Desktop - TPS54362EVM 28V to 5V @ 2.5A - 1163" was accepted I, 10928, 13, 2010/06/04, 09:38:38.914, 6972775597770, QTAgent32.exe, Playback - Element Found: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window' W, 10928, 13, 2010/06/04, 09:38:38.915, 6972775600035, QTAgent32.exe, PERF WARNING: FindTopLevelWindowHelper::FindAllDescendents: took 2043 ms. Expected it to take maximum 500 ms. I, 10928, 13, 2010/06/04, 09:38:38.926, 6972775629404, QTAgent32.exe, GetElementFromNativeElement() : MSAA, System.Object[] V, 10928, 13, 2010/06/04, 09:38:38.927, 6972775631298, QTAgent32.exe, Msaa : GetElementFromNativeElement V, 10928, 13, 2010/06/04, 09:38:38.927, 6972775633323, QTAgent32.exe, Msaa:WindowHandleGetter: MTA Thread returned valid Window handle [7018982] I, 10928, 13, 2010/06/04, 09:38:38.928, 6972775635829, QTAgent32.exe, ConvertToMappedPluginElement V, 10928, 13, 2010/06/04, 09:38:38.930, 6972775640707, QTAgent32.exe, AL : UITestControl.WaitForControlReady - 60000 ************************************** Window exists ************************************** I, 10928, 13, 2010/06/04, 09:38:38.933, 6972775647458, QTAgent32.exe, Playback - < Robustness level was set to '1' > V, 10928, 13, 2010/06/04, 09:38:38.934, 6972775649265, QTAgent32.exe, AL: Setting search timeout to 120000 ms I, 10928, 13, 2010/06/04, 09:38:39.034, 6972775909868, QTAgent32.exe, Playback - < Robustness level was set to '0' > V, 10928, 13, 2010/06/04, 09:38:39.035, 6972775913187, QTAgent32.exe, AL: Setting search timeout to 2000 ms V, 10928, 13, 2010/06/04, 09:38:39.036, 6972775915060, QTAgent32.exe, AL : GetProperty, propertyName: Exists V, 10928, 13, 2010/06/04, 09:38:39.036, 6972775917071, QTAgent32.exe, AL : EnsureValid() V, 10928, 13, 2010/06/04, 09:38:39.037, 6972775918851, QTAgent32.exe, AL : UITestControl.WaitForControlReady - 60000 ************************************** Window exists *************************************From the log, it seems that it correctly determines the window is gone:
W, 10928, 13, 2010/06/04, 09:38:35.835, 6972767580020, QTAgent32.exe, Playback - [WARNING] Internal warning: Window Not Found: [VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.Window
But then picks up a new window in its place:
W, 10928, 13, 2010/06/04, 09:38:38.906, 6972775577059, QTAgent32.exe, Playback - [WARNING] Internal warning: Window with Class "WindowsForms10.Window" and Title "SwitcherPro Desktop Splash Screen" was not found, so similar window with Class "WindowsForms10.Window.8.app.0.33c0d9d" and Title "SwitcherPro Desktop - TPS54362EVM 28V to 5V @ 2.5A - 1163" was accepted
I, 10928, 13, 2010/06/04, 09:38:38.914, 6972775597770, QTAgent32.exe, Playback - Element Found: ;[VisibleOnly]ControlType='Window' && Name='SwitcherPro Desktop Splash Screen' && ClassName=>'WindowsForms10.WindowSo it now thinks it found the "Splash Screen" when it actually found a different window. I believe this is why it "takes long time" to recognize the window is gone, because it picks up a new window and watches that one.
Is there a way to force it not to accept a similar window in this case?
-
Friday, June 04, 2010 3:28 PMModerator
Turn off the SmartMatch for Windows by doing
Playback
Please mark this post as answer if this answers your question.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None;- Proposed As Answer by Vishnu [MSFT]Microsoft Employee, Moderator Friday, June 04, 2010 3:29 PM
- Edited by Vishnu [MSFT]Microsoft Employee, Moderator Friday, June 04, 2010 3:30 PM formatting code
-
Friday, June 04, 2010 3:33 PMModerator
[For some reason, my previous reply's formatting is broken.]
Turn off the SmartMatch for Windows with this code.
Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None;
Please mark this post as answer if this answers your question- Marked As Answer by Brandon Hoppe Friday, June 04, 2010 3:45 PM
-
Friday, June 04, 2010 3:45 PMThanks Vishnu, that works! I now use in combination the SmartMatchOptions and the SearchTimeout.

