public void VerifyInput() { // // Start the application we are testing // string sampleAppPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "SampleApp.exe"); OutOfProcessSettings oops = new OutOfProcessSettings(new ProcessStartInfo(sampleAppPath), null, null); AutomatedApplication a = AutomatedApplication.Start(oops); try { a.WaitForMainWindow(TimeSpan.FromSeconds(10)); // // Discover various elements in the UI // AutomationElement inputTextBox = AutomationUtilities.FindElementsById(a.MainWindow, "inputTextBox")[0]; AutomationElement outputTextBox = AutomationUtilities.FindElementsById(a.MainWindow, "outputTextBox")[0]; AutomationElement appendButton = AutomationUtilities.FindElementsById(a.MainWindow, "appendButton")[0]; // // Click on the input text box and simulate typing // string inputText = "TestTest"; string expectedText = inputText + "\n"; WindowPattern winPattern = a.MainWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; Helpers.MoveToAndClick(inputTextBox); winPattern.WaitForInputIdle(1000); Microsoft.Test.Keyboard.Type(inputText); winPattern.WaitForInputIdle(1000); // // Now click the button // Helpers.MoveToAndClick(appendButton); winPattern.WaitForInputIdle(1000); // // Now, get the text of the outputTextBox and compare it against what's expected // Fail the test if expected != actual // TextPattern textPattern = outputTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string actualText = textPattern.DocumentRange.GetText(-1); // // Report the test result // Assert.AreEqual(expectedText, actualText); } finally { // // Close the tested application // a.Close(); } }
public void VerifyWindowAppearance() { // // Start the application we are testing // string sampleAppPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "SampleApp.exe"); OutOfProcessSettings oops = new OutOfProcessSettings(new ProcessStartInfo(sampleAppPath), null, null); AutomatedApplication a = AutomatedApplication.Start(oops); try { a.WaitForMainWindow(TimeSpan.FromSeconds(10)); // // Discover the checkbox in the UI, then click it // AutomationElement styleBox = AutomationUtilities.FindElementsById(a.MainWindow, "styleBox")[0]; Helpers.MoveToAndClick(styleBox); Thread.Sleep(1000); // Ensure that the Vista/Win7 window creation animation is complete // // Capture the window image and compare to the master image by generating a // diff image and processing the diff image with a tolerance color verifier // Snapshot master = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Master0.png")); Snapshot actual = Snapshot.FromWindow((IntPtr)a.MainWindow.Current.NativeWindowHandle, WindowSnapshotMode.ExcludeWindowBorder); Snapshot difference = actual.CompareTo(master); master.ToFile(@"Master0-expected.png", ImageFormat.Png); actual.ToFile(@"Master0-actual.png", ImageFormat.Png); difference.ToFile(@"Master0-difference.png", ImageFormat.Png); // // Report the test result // SnapshotVerifier verifier = new SnapshotColorVerifier(Color.Black, new ColorDifference(255, 18, 18, 18)); Assert.AreEqual(VerificationResult.Pass, verifier.Verify(difference)); } finally { // // Close the tested application // a.Close(); } }