Ejemplo n.º 1
0
    public void VerifyInput()
    {
        //
        // 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 various elements in the UI
            //
            AutomationElement inputTextBox  = AutomationUtilities.FindElementsById(a.MainWindow, "inputTextBox")[0];
            AutomationElement outputTextBox = AutomationUtilities.FindElementsById(a.MainWindow, "outputTextBox")[0];
            AutomationElement appendButton  = AutomationUtilities.FindElementsById(a.MainWindow, "appendButton")[0];

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

            WindowPattern winPattern = a.MainWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
            Helpers.MoveToAndClick(inputTextBox);
            winPattern.WaitForInputIdle(1000);
            Microsoft.Test.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();
        }
    }
Ejemplo n.º 2
0
    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();
        }
    }
Ejemplo n.º 3
0
        protected void CloseHelper()
        {
            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            // test closing down the app
            Debug.WriteLine("close the main window");
            TestAutomatedApp.Close();

            Assert.Null(TestAutomatedApp.MainWindow);

            if (TestAutomatedApp is InProcessApplication)
            {
                Assert.Null((TestAutomatedApp as InProcessApplication).ApplicationDriver);
            }

            TestAutomatedApp = null;
        }
Ejemplo n.º 4
0
        protected void OnExitHelper()
        {
            bool exitedFired = false;

            TestAutomatedApp.Exited += (s2, e2) =>
            {
                Debug.WriteLine("Exited fired.");
                exitedFired = true;
            };

            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            // test closing down the app
            Debug.WriteLine("close the main window");
            TestAutomatedApp.Close();
            TestAutomatedApp = null;

            Assert.True(exitedFired, "Exited event did not fire.");
        }
Ejemplo n.º 5
0
        public void FixtureSetUp()
        {
            _onWorkerOneProcess = Start(GetPathFromConfig("PingApp-worker-exe-file"), WorkerService);
            _onWorkerTwoProcess = Start(GetPathFromConfig("PongApp-worker-exe-file"), WorkerService);

            var _pingCallBackHandler = new ExecutorCallbackService();
            var _pongCallBackHandler = new ExecutorCallbackService();

            _onWorkerOne = OnWorker.FromEndpointConfigNames("PingApp-AssemblyManager", "PingApp-Executor", _pingCallBackHandler);
            _onWorkerTwo = OnWorker.FromEndpointConfigNames("PongApp-AssemblyManager", "PongApp-Executor", _pongCallBackHandler);

            Instruction <Tuple <string, string>, bool> openApp1 = (ct, rp, args) => OpenApp(ct, rp, args.Item1);
            Instruction <Tuple <string, string>, bool> openApp2 = (ct, rp, args) => OpenApp(ct, rp, args.Item2);

            pingPath = GetPathFromConfig("PingApp-exe-file");
            pongPath = GetPathFromConfig("PongApp-exe-file");

            var tuple = new Tuple <string, string>(pingPath + @"\PingApp.exe", pongPath + @"\PongApp.exe");

            DistrEx.Coordinator.Coordinator.Do(_onWorkerOne.Do(openApp1), _onWorkerTwo.Do(openApp2), tuple);
        }
Ejemplo n.º 6
0
        protected void OnExitViaAddHandlerHelper()
        {
            bool exitedFired = false;

            TestAutomatedApp.AddEventHandler(
                AutomatedApplicationEventType.ApplicationExitedEvent,
                new EventHandler <AutomatedApplicationEventArgs>((s, e) =>
            {
                Debug.WriteLine("Exited fired.");
                exitedFired = true;
            }));

            Debug.WriteLine("starting automated app...");
            TestAutomatedApp.Start();
            TestAutomatedApp.WaitForMainWindow(DefaultTimeoutTimeSpan);

            // test closing down the app
            Debug.WriteLine("close the main window");
            TestAutomatedApp.Close();
            TestAutomatedApp = null;

            Assert.True(exitedFired, "Exited event did not fire.");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// blocks until closed
 /// </summary>
 /// <param name="process"></param>
 internal static void Stop(AutomatedApplication process)
 {
     process.Close();
 }
 /// <summary>
 /// Initializes a new instance of the AutomatedApplicationFocusChangedEventArgs
 /// class.
 /// </summary>
 /// <param name="automatedApp">
 /// The AutomatedApplication data to pass to the listeners.
 /// </param>
 /// <param name="newFocusedElement">
 /// The new focused element data to pass the listeners. This can be an AutomationElement
 /// for an out-of-process scenario or a UIElement for an in-process WPF scenario.
 /// </param>
 public AutomatedApplicationFocusChangedEventArgs(AutomatedApplication automatedApp, object newFocusedElement)
     : base(automatedApp)
 {
     NewFocusedElement = newFocusedElement;
 }
Ejemplo n.º 9
0
 public void StartHost()
 {
     _hostProcess = HostProcessHelper.Start();
 }