private void BuildElementTable(UIA.AutomationElement _originalElement) { Assembly assembly = Assembly.GetAssembly(typeof(UIA.AutomationElement)); Assembly curAssembly = Assembly.GetCallingAssembly(); // Get all patterns currently supported by UIA if (_patterns == null) _patterns = GetPatternList(); try { // Use refelction to build up the list of elements foreach (UIA.AutomationElement element in _originalElement.FindAll(UIA.TreeScope.Subtree, UIA.Condition.TrueCondition)) { // Everything supports the AutomationElement "pattern" so add them // as AutomationStressTests.AutomationElement _contextElements.Add(new AutomationElement(element)); // If the AutomationElement supports a specific pattern, then // create an UIAutomationTestTypes based on the specific // pattern that is supported. If the AutomationElement // supports more than one pattern, then create another // UIAutomationTestTypes of the other patterns and store them // for later retrieval using the GetRandomObjectByType() foreach (string patternName in _patterns) { // Get the particular Is<Pattern>Supported property such as IsScrollPatternSupported FieldInfo fi = assembly.GetType("System.Windows.Automation.AutomationElement").GetField("Is" + patternName + "AvailableProperty"); // Use the property to get the actual value of the Is<Pattern>Supported // associated with the specific AutomationElement if ((bool)element.GetCurrentPropertyValue((UIA.AutomationProperty)fi.GetValue(element))) { // If it's not the close button, create the AutomationStressTests.<Pattern> and store // it in the context for later retrieval using GetRandomObjectByType() if (patternName != UIA.InvokePattern.Pattern.ProgrammaticName && element.Current.Name != "Close") { _appCommands.TraceMethod("Creating UIAStressHelpers." + patternName); _contextElements.Add(Activator.CreateInstance(curAssembly.GetType("UIAStressHelpers." + patternName), new object[] { element })); } } } } } catch (InvalidCastException e) { System.Diagnostics.Debug.Assert(false); Console.WriteLine(e.ToString()); } }