public void ZoomInOnce() { string toleranceFile = @"ToleranceMap1280x768.png"; string masterFile = @"Master1280x768.png"; if (SystemParameters.PrimaryScreenWidth == 1280 && SystemParameters.PrimaryScreenHeight == 800) { toleranceFile = @"ToleranceMap1280x800.png"; masterFile = @"Master1280x800.png"; } new ZoomButtons(metlWindow.AutomationElement).ZoomIn(); // verify zoom var tolerance = Snapshot.FromFile(toleranceFile); var master = Snapshot.FromFile(masterFile); var actual = Snapshot.FromWindow((IntPtr)metlWindow.AutomationElement.Current.NativeWindowHandle, WindowSnapshotMode.ExcludeWindowBorder); var diff = actual.CompareTo(master); master.ToFile(@"Master-expected.png", ImageFormat.Png); actual.ToFile(@"Master-actual.png", ImageFormat.Png); diff.ToFile(@"Master-difference.png", ImageFormat.Png); var verifier = new SnapshotToleranceMapVerifier(tolerance); Assert.AreEqual(VerificationResult.Pass, verifier.Verify(diff)); }
public void VerifyScreenshot(string filename) { Snapshot actual = Snapshot.FromFile(filename + "." + _currentImageFormat); Snapshot master = Snapshot.FromFile(Masters + filename + "." + _currentImageFormat); Snapshot toleranceMap = Snapshot.FromFile(ToleranceMaps + filename + "." + _currentImageFormat); Snapshot difference = actual.CompareTo(master); SnapshotVerifier verifier = new SnapshotToleranceMapVerifier(toleranceMap); Assert.AreEqual(VerificationResult.Pass, verifier.Verify(difference)); }
public void VerifyWindowAppearance() { // // Start the application we are testing // string sampleAppPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "SampleApp.exe"); AutomatedApplication a = new OutOfProcessApplication(new OutOfProcessApplicationSettings { ProcessStartInfo = new ProcessStartInfo(sampleAppPath), ApplicationImplementationFactory = new UIAutomationOutOfProcessApplicationFactory() }); a.Start(); try { a.WaitForMainWindow(TimeSpan.FromSeconds(10)); Thread.Sleep(1000); // Ensure that the Vista/Win7 window creation animation is complete var mainWindow = a.MainWindow as AutomationElement; // // Discover the checkbox in the UI, then click it // AutomationElement styleBox = AutomationUtilities.FindElementsById(mainWindow, "styleBox")[0]; Helpers.MoveToAndClick(styleBox); // // Capture the window image and compare to the master image by generating a // diff image and processing the diff image with a tolerance map verifier // Snapshot toleranceMap = Snapshot.FromFile("ToleranceMap.png"); Snapshot master = Snapshot.FromFile("Master.png"); Snapshot actual = Snapshot.FromWindow((IntPtr)mainWindow.Current.NativeWindowHandle, WindowSnapshotMode.ExcludeWindowBorder); Snapshot difference = actual.CompareTo(master); master.ToFile(@"Master-expected.png", ImageFormat.Png); actual.ToFile(@"Master-actual.png", ImageFormat.Png); difference.ToFile(@"Master-difference.png", ImageFormat.Png); // // Report the test result // SnapshotVerifier verifier = new SnapshotToleranceMapVerifier(toleranceMap); Assert.AreEqual(VerificationResult.Pass, verifier.Verify(difference)); } finally { // // Close the tested application // a.Close(); } }