//should I only make automationElement and actionListener once? public static UIItem GetControl(Point point) { POINT point1 = new POINT(point.X, point.Y); IntPtr myIntPtr = WindowFromPoint(point1); AutomationElement automationElement = AutomationElement.FromHandle(myIntPtr); automationElement = GetChildControl(point, automationElement) ?? automationElement; TreeWalker walker = TreeWalker.ControlViewWalker; AutomationElement parentElement = walker.GetParent(automationElement); if (parentElement != null && parentElement.Current.LocalizedControlType == "button") automationElement = parentElement; int delNum; while(((string.IsNullOrEmpty(automationElement.Current.Name) && string.IsNullOrEmpty(automationElement.Current.AutomationId)) || int.TryParse(automationElement.Current.AutomationId, out delNum))) { automationElement = walker.GetParent(automationElement); } ActionListener actionListener = new NullActionListener(); return new UIItem(automationElement, actionListener); }
public void SetUp() { launcher = new ApplicationLauncher(TimeSpan.Parse("00:00:12")); application = launcher.LaunchOrRecycle("Example.PetShop.WinForms", @"Examples\WinForms\Example.PetShop.WinForms.exe", null); WindowFactory.ControlConstructor = new WindowFactory.ConstructFromElement((controlType, element, name) => { if (controlType.Namespace.Contains("WiPFlash")) { Object[] parameters = new Object[2]; parameters[0] = element; parameters[1] = name; return ReflectionHelper.Instantiate(controlType.Assembly, controlType.FullName, parameters); } else if (controlType.Namespace.Contains("TestStack.White")) { Object[] parameters = new Object[2]; parameters[0] = element; parameters[1] = new TestStack.White.UIItems.Actions.NullActionListener(); return ReflectionHelper.Instantiate(controlType.Assembly, controlType.FullName, parameters); } throw new CreatePlaceHeldControlFailedException(String.Format("Control Namespace Not Recognised!\nNamespace: {0}", controlType.Namespace), null); }); }