From c3c21c854489c95443c31e0539a8a8a60ba6ea62 Mon Sep 17 00:00:00 2001 From: ivan-danilov Date: Tue, 5 Nov 2013 16:49:00 +0200 Subject: [PATCH] Added Application main window activation after process startup. Sometimes, especially when White-driven UI test started from console shell or another programmatic way, OS launches application under test in the background and test fails because of this. This commit fixes the problem. --- src/TestStack.White/Application.cs | 3 +++ src/TestStack.White/WindowsAPI/NativeWindow.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/TestStack.White/Application.cs b/src/TestStack.White/Application.cs index 1969acb4..f887a4da 100644 --- a/src/TestStack.White/Application.cs +++ b/src/TestStack.White/Application.cs @@ -10,6 +10,7 @@ using TestStack.White.Sessions; using TestStack.White.UIItems.Finders; using TestStack.White.UIItems.WindowItems; +using TestStack.White.WindowsAPI; namespace TestStack.White { @@ -78,6 +79,8 @@ public static Application Launch(ProcessStartInfo processStartInfo) Logger.Error(error, ex); throw; } + process.WaitForInputIdle(CoreAppXmlConfiguration.Instance.BusyTimeout); + NativeWindow.SetForegroundWindow(process.MainWindowHandle); //TODO Expose this, and make it capture output properly if (ConfigurationManager.AppSettings["CaptureAUTOutput"] != null) { diff --git a/src/TestStack.White/WindowsAPI/NativeWindow.cs b/src/TestStack.White/WindowsAPI/NativeWindow.cs index f8ce0006..325c686b 100644 --- a/src/TestStack.White/WindowsAPI/NativeWindow.cs +++ b/src/TestStack.White/WindowsAPI/NativeWindow.cs @@ -20,6 +20,9 @@ public class NativeWindow [DllImport("gdi32.dll")] private static extern COLORREF GetTextColor(IntPtr hdc); + [DllImport("user32.dll")] + public static extern bool SetForegroundWindow(IntPtr hWnd); + public NativeWindow(Point point) { handle = WindowFromPoint(new POINT((int) point.X, (int) point.Y));