/// <summary> /// Run Testcase /// </summary> /// <param name="testcase"></param> /// <param name="targetControlName"></param> public void RunTestcase(UiaDistributedTestcase testcase, string targetControlName) { EnsureState(); //get the top window element AutomationElement topWindowElement = AutomationElement.FromHandle(hWndHost); //get the UIElement AutomationElement clientElement = topWindowElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, targetControlName)); #if TESTBUILD_CLR40 //Since we could not find the element we were looking for, there is a chance it is virtualized //This only applies to .NET 4.0 and above assuming UIACore 7 is also present. if ((clientElement == null) && (AutomationElement.IsItemContainerPatternAvailableProperty != null)) { //here we will find all elements that are item containers and therefore might contain virtualized items AutomationElementCollection elementCollection = topWindowElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.IsItemContainerPatternAvailableProperty, true)); for (int i = 0; i < elementCollection.Count; i++) { ItemContainerPattern itemContainerPattern = elementCollection[i].GetCurrentPattern(ItemContainerPattern.Pattern) as ItemContainerPattern; // look for the item we are searching for in each container clientElement = itemContainerPattern.FindItemByProperty(null, AutomationElement.AutomationIdProperty, targetControlName); if (clientElement != null) { break; } } } #endif //perform the test testcase.RunTest(remoteHost, clientElement, targetControlName); }
/// <summary> /// Attach Testcase /// </summary> /// <param name="testcase"></param> /// <param name="name"></param> public void AttachTestcase(UiaDistributedTestcase testcase, string name) { this.currentTest = testcase; //HACK: need to marshal the exception back to this thread because Invoke does not do it for us //need to invoke this on the dispatcher thread synchonously Exception e = (Exception)dispatcher.Invoke(DispatcherPriority.Background, (MarshalExceptionCallback) delegate() { try { if (name != null) { if (testWindow.Content as FrameworkElement != null) { target = ((FrameworkElement)testWindow.Content).FindName(name); } else if (testWindow.Content as FrameworkContentElement != null) { target = ((FrameworkContentElement)testWindow.Content).FindName(name); } else { target = null; } if (target == null) { throw new ArgumentException("Could not find an element with the id " + name, "id"); } } } catch (Exception err) { return(err); } return(null); }); if (e != null) { throw new Exception("An Unhandled Exception Occurred on the Avalon Thread", e); } }