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"));
}