Quiet test failures on Vista

Jul 3, 2009 at 12:11 AM

I've run into a quirky issue with application window focus when running tests with the following setup:

  • Vista SP1
  • .NET 3.5 SP1
  • WinForms App
  • Running tests from nunit-console

When I run tests from a console window and the console window has focus/is topmost everything works fine. When another window besides the console window has focus at the time the tested application starts, attempts to find components on the tested application window fail quietly.

For example, the code below will proceed quietly with no errors until throwing a null-reference exception on the last line:

 

Application myApp = Application.Launch("MyApp.exe");
Window mainWindow = myApp.GetWindow(SearchCriteria.ByAutomationId("MainForm"), InitializeOption.NoCache);
mainWindow.MenuBar.MenuItem("File").Click();
Window modal = mainWindow.ModalWindow("myModalWindow");
modalWindow.Get<Label>("some label);
  1. The app starts but the window is not top-most.
  2. The Application.GetWindow() call returns a window reference.
  3. MenuBar.MenuItem.Click() hangs unitl the BusyTimeout expires and then proceeds with no timeout exception.
  4. mainWindow.ModalWindow() hangs and then proceeds with no error, but does not actually return the modal window (which doesn't exist because the menu item was never clicked).

The only way I've found to eliminate this is to call Window.Focus() after getting the main window.

Just to be clear:

  1. There is no user mouse or keyboard activity going on during the test.
  2. The exact same code works fine 100% of the time when the console window has initial focus and fails 100% of the time when it does not have focus.

I'm fine with the Focus() workaround, but this did cost me a fair bit of time and is frustrating because of its intermittent nature. I thought it was worth pointing out to help other folks and in case a fix can be implemented in White itself.

Regards,

Ashley

 

 

Coordinator
Jul 4, 2009 at 10:39 AM

May be number 3 here. http://white.codeplex.com/Wiki/View.aspx?title=Other%20questions

Jul 4, 2009 at 6:32 PM

It's not #3 on that discussion. The test works 100% of the time when the console window has initial focus and fails 100% when another window has initial focus. Also, the issue affects calls to get other components besides MenuItems and doesn't report any find-failure--just returns from the get call with no errors.

Coordinator
Jul 5, 2009 at 11:09 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.