UiaControlsTest.TargetApp.Start C# (CSharp) Method

Start() public method

public Start ( ) : void
return void
        public void Start()
        {
            if (TryOpenExisting())
            {
                _ownProcess = false;
                WaitForWindow();
                return;
            }
            if (_debug)
            {
                Console.WriteLine("Debug mode:");
                Console.WriteLine("Start the following process manually, and enter the PID when done,");
                Console.WriteLine("or hit Enter to start the process automatically");
                Console.WriteLine("  " + _cmdLine + " " + _args);

                for (;;)
                {
                    var str = Console.ReadLine();

                    if (str == "")
                    {
                        _p = Process.Start(_cmdLine, _args);
                        Console.WriteLine("App started - pause to attach debugger - hit Enter to continue");
                        Console.ReadLine();
                        break;
                    }
                    try
                    {
                        var id = Int32.Parse(str);

                        _p = Process.GetProcessById(id);
                        _ownProcess = false;
                        break;
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Invalid int - try again");
                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine("Bad Process ID - try again");
                    }
                }
            }
            else
            {
                _p = Process.Start(_cmdLine, _args);
                _ownProcess = true;
            }

            // _p.WaitForInputIdle(); - doesn't work for non-GUI apps - Instead, wait for the window to appear, then use this.

            WaitForWindow();
        }

Usage Example

        public void MyTestInitialize()
        {
            // Create the factory and register schemas
            _nFactory = new CUIAutomationClass();

            // Start the app
            var curDir = Environment.CurrentDirectory;
            _app = new TargetApp(curDir + "\\WpfAppWithAdvTextControl.exe");
            _app.Start();

            // Find the main control
            var appElement = _nFactory.ElementFromHandle(_app.MainWindow);

            var advTestBoxCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "advTextBox1");
            _nAdvancedTextBoxElement = appElement.FindFirst(NTreeScope.TreeScope_Children, advTestBoxCondition);
            Assert.IsNotNull(_nAdvancedTextBoxElement);

            var testControlCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "testControl");
            _nTestControlElement = appElement.FindFirst(NTreeScope.TreeScope_Children, testControlCondition);
            Assert.IsNotNull(_nTestControlElement);

            var window = AutomationElement.RootElement.FindFirst(WTreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "MainWindow"));
            _wAdvancedTextBoxElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "advTextBox1"));
            _wTestControlElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "testControl"));
        }
All Usage Examples Of UiaControlsTest.TargetApp::Start