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();
        }
    }
示例#2
0
        public void FaultAppendText()
        {
            //This is a work-around, Xunit moves the reference dll's at run time so we need to call register
            //from the test, instead of TestApiCore.
            string processorArch = DetectProccessorArchitecture();

            ComRegistrar.Register(@".\FaultInjectionEngine\" + processorArch + @"\FaultInjectionEngine.dll");

            string sampleAppPath = "SampleApp.exe";

            //Create the FaultRule and FaultSession
            FaultRule rule = new FaultRule(
                "SampleApp.Window1.Append(string, string)",
                BuiltInConditions.TriggerOnEveryCall,
                BuiltInFaults.ReturnValueFault(""));

            FaultSession session = new FaultSession(rule);

            //Start the app
            ProcessStartInfo        psi     = session.GetProcessStartInfo(sampleAppPath);
            OutOfProcessApplication testApp = new OutOfProcessApplication(
                new OutOfProcessApplicationSettings
            {
                ProcessStartInfo = psi,
                ApplicationImplementationFactory = new UIAutomationOutOfProcessApplicationFactory()
            });

            testApp.Start();


            try
            {
                testApp.WaitForMainWindow(TimeSpan.FromSeconds(15));

                // Discover various elements in the UI
                AutomationElement mainWindowElement = (AutomationElement)testApp.MainWindow;
                AutomationElement inputTextBox      = AutomationUtilities.FindElementsById(mainWindowElement, "inputTextBox")[0];
                AutomationElement outputTextBox     = AutomationUtilities.FindElementsById(mainWindowElement, "outputTextBox")[0];
                AutomationElement appendButton      = AutomationUtilities.FindElementsById(mainWindowElement, "appendButton")[0];

                // Click on the input text box and simulate typing
                string inputText    = "TestTest";
                string expectedText = ""; //expected text should be nothing since we intercept the Append method

                WindowPattern winPattern = mainWindowElement.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
                Helpers.MoveToAndClick(inputTextBox);
                winPattern.WaitForInputIdle(inputWaitTime);
                Microsoft.Test.Input.Keyboard.Type(inputText);
                winPattern.WaitForInputIdle(inputWaitTime);

                // Now click the button
                Helpers.MoveToAndClick(appendButton);
                winPattern.WaitForInputIdle(inputWaitTime);

                // Now, get the text of the outputTextBox and compare it against what's expected
                // Fail the test if expected != actual
                TextPattern textPattern = outputTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
                string      actualText  = textPattern.DocumentRange.GetText(-1);

                // Report the test result
                Assert.Equal <string>(expectedText, actualText);
            }
            finally
            {
                // Close the tested application
                testApp.Close();
            }
        }
示例#3
0
    public void VerifyInput()
    {
        //
        // 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));
            var mainWindow = a.MainWindow as AutomationElement;

            //
            // Discover various elements in the UI
            //
            AutomationElement inputTextBox  = AutomationUtilities.FindElementsById(mainWindow, "inputTextBox")[0];
            AutomationElement outputTextBox = AutomationUtilities.FindElementsById(mainWindow, "outputTextBox")[0];
            AutomationElement appendButton  = AutomationUtilities.FindElementsById(mainWindow, "appendButton")[0];

            //
            // Click on the input text box and simulate typing
            //
            string inputText    = "TestTest";
            string expectedText = inputText + "\n";

            WindowPattern winPattern = mainWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
            Helpers.MoveToAndClick(inputTextBox);
            winPattern.WaitForInputIdle(1000);
            Microsoft.Test.Input.Keyboard.Type(inputText);
            winPattern.WaitForInputIdle(1000);

            //
            // Now click the button
            //
            Helpers.MoveToAndClick(appendButton);
            winPattern.WaitForInputIdle(1000);

            //
            // Now, get the text of the outputTextBox and compare it against what's expected
            // Fail the test if expected != actual
            //
            TextPattern textPattern = outputTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
            string      actualText  = textPattern.DocumentRange.GetText(-1);

            //
            // Report the test result
            //
            Assert.AreEqual(expectedText, actualText);
        }
        finally
        {
            //
            // Close the tested application
            //
            a.Close();
        }
    }