Feb 11, 2010 at 1:50 PM
Edited Feb 15, 2010 at 8:58 AM
I have big problems testing my WinForm (NET 3.5). First of all, I have due to explizit demand NO application to be able to be launched. Currently I generate my UI to be tested from within my test. That sounds strange, but this is what we need this for our
So my tests starts like this:
private void ShowFormFromThread()
public void TestMenuItems()
Thread showMainFormAsDialogFromThread = new Thread( new ThreadStart( ShowFormFromThread ) );
So my Form is visible in a correct way. I started it from a thread to be able to show it with ShowDialog(). Else my testapp would hang. No I want to get the window-object, but no approach worked for me. Desktop.Instance.Windows and the direct way run always
in a timeout.
So I tried this:
private AutomationElement GetMainWindow()
AutomationElement aeDesktop = AutomationElement.RootElement;
AutomationElement aeMainForm = null;
int numWaits = 0;
aeMainForm = aeDesktop.FindFirst( TreeScope.Children, new PropertyCondition( AutomationElement.NameProperty, MYNAME ) );
Thread.Sleep( 200 );
} while( aeMainForm == null && numWaits < 50 );
if( aeMainForm == null )
throw new Exception( "Can't find form" );
This gives me an AutomationElement. No I started to get the MenuBar and the MenuItems. This isnt working, my Spy-Tools (UISpy and Visual UI Automation Verify) are also freezing when I want to access my window.
When I start my window from it's real application (I tried this just for testing, this is no option unfortunately), then it works fine.
My window is instaciated properly and the menu items are working as expected, when I click them manually. But I can't automate a thing.
My problems are mostly based on the strange approach of starting our window-under-test from within the test itself, but can anybody give me some advice how to workaround this issue without beeing forced to start an application?
Thank you very much,