http://blogs.msdn.com/b/gautamg/archive/2010/04/08/how-to-do-image-comparison-in-coded-ui-test.aspx
[TestMethod]
[DeploymentItem("Master.png")]
[DeploymentItem("ToleranceMap.png")]
[DeploymentItem("SampleApp.exe")]
public void CompareImagesTest()
{
// Launch the application.
using (ApplicationUnderTest app = ApplicationUnderTest.Launch(
Path.Combine(Directory.GetCurrentDirectory(),
"SampleApp.exe")))
{
// Select the check box, so that the background will change.
WpfCheckBox checkBox = new WpfCheckBox(app);
checkBox.Checked = true;
// Get the actual, master and toleracne snapshots.
Snapshot toleranceMap =
Snapshot.FromFile("ToleranceMap.png");
Snapshot master = Snapshot.FromFile("Master.png");
Snapshot actual = Snapshot.FromWindow(app.WindowHandle,
WindowSnapshotMode.ExcludeWindowBorder);
// Get the difference of two images.
Snapshot difference = actual.CompareTo(master);
// Save the file to for manual viewing.
master.ToFile(@"Master-expected.png", ImageFormat.Png);
actual.ToFile(@"Master-actual.png", ImageFormat.Png);
difference.ToFile(@"Master-difference.png",
ImageFormat.Png);
// Use SnapshotToleranceMapVerifier to verify the comparison.
SnapshotVerifier verifier =
new SnapshotToleranceMapVerifier(toleranceMap);
Assert.AreEqual(VerificationResult.Pass,
verifier.Verify(difference));
Комментариев нет:
Отправить комментарий