public void VerifyWindowAppearance() { ApplicationDriver driver = new ApplicationDriver(typeof(SampleApp.App)); driver.WaitForIdleUi(); AutomationElement window = AutomationUtilities.FindElementsById(AutomationElement.RootElement, "sampleAppWindow")[0]; AutomationElement styleBox = AutomationUtilities.FindElementsById(window, "styleBox")[0]; AutomationElement captureRegion = AutomationUtilities.FindElementsById(window, "captureContainer")[0]; AutomationHelpers.MoveToAndClick(styleBox); driver.WaitForIdleUi(); try { // Capture the actual pixels from the bounds of the screen rectangle Snapshot actual = Snapshot.FromRectangle(AutomationHelpers.GetElementSize(captureRegion)); LogFile(actual, "Actual.png"); // Load the reference/master data from a previously saved file Snapshot master = Snapshot.FromFile(Path.Combine(TestContext.TestDeploymentDir, "Master0.png")); LogFile(master, "Master.png"); // Log the outcome of the test, only on failure to save disk space. // For test stability in scenarios of varying window styles, consider: // -cropping the capture region to eliminate the border rectangle // -Testing on a well controlled test environment if (CompareImages(actual, master) == VerificationResult.Fail) { Assert.Fail("Initial State test failed. Actual should look like Master image. Refer to logged images under:" + TestContext.TestLogsDir); } } finally { AutomationHelpers.CloseWindow(window); driver.Join(); } }