From what I understand, the best approach is to break up your tasks as small as possible. So for a UI test I did that opens a shortcut on my toolbar, clicks login on a popup within, then clicks a tab in the application, the code looks like this:
namespace CodedUITestProject1 { /// <summary> /// Summary description for CodedUITest1 /// </summary> [CodedUITest] public class CodedUITest1 { public CodedUITest1() { } [TestMethod] public void CodedUITestMethod1() { // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463 this.UIMap.OpenWindow(); this.UIMap.ClickLogin(); this.UIMap.ClickDevelopment(); } //snip }
So then in the ClickDevelopment() method, I know that the program should be visible, so rather than just dive right into the method actions, I can throw a Thread.Sleep() to make it visible for a little while longer.
public void ClickDevelopment() { Thread.Sleep(10000); #region Variable Declarations WinClient uIDevelopmentClient = this.UIQualityTrack30Window.UIItemWindow.UIQualityTrack30Client.UIDevelopmentClient; #endregion // Click 'Development' client Mouse.Click(uIDevelopmentClient, new Point(39, 52)); }
CodedUi Test(e.g. clicking 'close' button) or by the Application Under Test itself?