private bool AreImagesSame(Bitmap firstImage, Bitmap secondImage) { Snapshot actual = Snapshot.FromBitmap(firstImage); Snapshot expected = Snapshot.FromBitmap(secondImage); Snapshot difference = actual.CompareTo(expected); SnapshotVerifier v = new SnapshotColorVerifier(Color.Black, new ColorDifference()); return(v.Verify(difference) == VerificationResult.Pass); }
public void DefaultConstructor() { SnapshotColorVerifier v = new SnapshotColorVerifier(); Assert.Equal <byte>(Color.Black.A, v.ExpectedColor.A); Assert.Equal <byte>(Color.Black.R, v.ExpectedColor.R); Assert.Equal <byte>(Color.Black.G, v.ExpectedColor.G); Assert.Equal <byte>(Color.Black.B, v.ExpectedColor.B); Assert.Equal <byte>(0, v.Tolerance.A); Assert.Equal <byte>(0, v.Tolerance.R); Assert.Equal <byte>(0, v.Tolerance.G); Assert.Equal <byte>(0, v.Tolerance.B); }
/// <summary> /// Compares an actual image against a master image /// If all pixels match, the operation will pass /// </summary> /// <param name="actual"></param> /// <param name="master"></param> private VerificationResult CompareImages(Snapshot actual, Snapshot master) { // Compare the actual image with the master image Snapshot difference = actual.CompareTo(master); LogFile(difference, "Difference.png"); // Configure the snapshot verifier - It expects a black image with ~7.5% color tolerance to detect human visible differences SnapshotColorVerifier colorVerifier = new SnapshotColorVerifier(Color.Black, new ColorDifference(255, 18, 18, 18)); // Evaluate the difference image and retun the result return(colorVerifier.Verify(difference)); }
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(); } }
public void Cleanup() { try { if (numShots < maxShots) //Stop captures once we've hit 50 image { WaitForRender(); Snapshot current = Capture(); if (previous == null) { LogImage(current, logDirectory, "Baseline_Post_Execution_Snapshot.png"); } else { Snapshot diff = previous.CompareTo(current); SnapshotVerifier verifier = new SnapshotColorVerifier(); if (verifier.Verify(diff) == VerificationResult.Fail) // Give test benefit of doubt, and re-capture. GDI is known to be glitchy on propagating first snap. { WaitForRender(); current = Capture(); diff = previous.CompareTo(current); if (verifier.Verify(diff) == VerificationResult.Fail) { LogImage(current, logDirectory, "Current_Post_Execution_Snapshot.png"); LogImage(diff.Resize(downsampleSize), logDirectory, "Delta_Post_Execution_Snapshot.png"); Logging.LoggingMediator.LogEvent("Desktop snapshot appears to be different from state of previously capture."); numShots++; } } } previous = current; //Now, the current image becomes the new previous. } } catch (Exception) { ExecutionEventLog.RecordStatus("Error on attempting Desktop Snapshot Command - Was the desktop locked or the context otherwise unavailable?"); } }
public void VerifyHistogram() { // // Load up a pair of high-information content images and compare them // Snapshot master = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Mandelbrot01.png")); Snapshot compare = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Mandelbrot02.png")); Snapshot difference = compare.CompareTo(master); // // Generate a histogram from the diff image // Histogram h = Histogram.FromSnapshot(difference); // // Save out the line graph of the histogram as a lossless png // h.ToGraph(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Histogram-Graph-Actual.png"), ImageFormat.Png); // // Load the graph image into memory so that we can compare it to a known good version // Snapshot graphImage = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Histogram-Graph-Actual.png")); // // Compare the rendered graph to a known good render // Snapshot expectedGraph = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Histogram-Graph-Expected.png")); Snapshot graphDifference = expectedGraph.CompareTo(graphImage); // // There should be absolutely no differences between the graph and the expected graph // Microsoft.Test.VisualVerification.ColorDifference colorDiff = new ColorDifference(0, 0, 0, 0); SnapshotColorVerifier verifier = new SnapshotColorVerifier(System.Drawing.Color.Black, colorDiff); VerificationResult result = verifier.Verify(graphDifference); Assert.Equal <VerificationResult>(VerificationResult.Pass, result); }
public void ParameterizedConstructor(string expectedColorString, string toleranceString) { int expectedColor = Int32.Parse(expectedColorString, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); int tolerance = Int32.Parse(toleranceString, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); Color c = Color.FromArgb((int)expectedColor); byte ta = (byte)(tolerance & 0xFF000000 >> 128); byte tr = (byte)(tolerance & 0x00FF0000 >> 32); byte tg = (byte)(tolerance & 0x0000FF00 >> 16); byte tb = (byte)(tolerance & 0x000000FF >> 0); ColorDifference t = new ColorDifference(ta, tr, tg, tb); SnapshotColorVerifier v = new SnapshotColorVerifier(c, t); Assert.Equal <byte>(c.A, v.ExpectedColor.A); Assert.Equal <byte>(c.R, v.ExpectedColor.R); Assert.Equal <byte>(c.G, v.ExpectedColor.G); Assert.Equal <byte>(c.B, v.ExpectedColor.B); Assert.Equal <byte>(t.A, v.Tolerance.A); Assert.Equal <byte>(t.R, v.Tolerance.R); Assert.Equal <byte>(t.G, v.Tolerance.G); Assert.Equal <byte>(t.B, v.Tolerance.B); }