Ejemplo n.º 1
0
        public void VerifyInput()
        {
            AutomationElement rootElement;
            Process           appProcess = AutomationHelpers.StartProcess(new ProcessStartInfo("SampleApp.exe"), out rootElement);

            AutomationElement inputTextBox  = AutomationUtilities.FindElementsById(rootElement, "inputTextBox")[0];
            AutomationElement outputTextBox = AutomationUtilities.FindElementsById(rootElement, "outputTextBox")[0];
            AutomationElement button        = AutomationUtilities.FindElementsById(rootElement, "appendButton")[0];

            string inputText    = "TestTest";
            string expectedText = inputText + "\n";

            WindowPattern winPattern = (WindowPattern)rootElement.GetCurrentPattern(WindowPatternIdentifiers.Pattern);

            AutomationHelpers.MoveToAndClick(inputTextBox);
            winPattern.WaitForInputIdle(1000);
            Microsoft.Test.Keyboard.Type(inputText);
            winPattern.WaitForInputIdle(1000);
            AutomationHelpers.MoveToAndClick(button);
            winPattern.WaitForInputIdle(1000);

            object o;

            outputTextBox.TryGetCurrentPattern(TextPatternIdentifiers.Pattern, out o);
            TextPattern pattern    = (TextPattern)o;
            string      actualText = pattern.DocumentRange.GetText(-1);

            try
            {
                Assert.AreEqual(expectedText, actualText, "The text did not match. Expected: {0}  Actual: {1}", expectedText, actualText);
            }
            finally
            {
                AutomationHelpers.CloseWindow(rootElement);
                appProcess.WaitForExit();
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }