Пример #1
0
        public static List <AutomationElement> ConditionLocator(UIATestObject testObject)
        {
            _Logger.WriteDebug("ConditionLocator start");
            Condition condition = testObject.GetCondition();

            if (condition == null)
            {
                condition = TreeWalker.ControlViewWalker.Condition;
            }

            List <AutomationElement> elementList = new List <AutomationElement>();

            UIATestObject parentTestObject = (UIATestObject)testObject.Parent;

            if (parentTestObject == null)
            {
                //root object
                AutomationElement windowElement = AutomationElement.RootElement.FindFirst(TreeScope.Children,
                                                                                          condition);
                if (windowElement != null)
                {
                    elementList.Add(windowElement);
                }

                /*
                 * AutomationElementCollection windowElements = AutomationElement.RootElement.FindAll(TreeScope.Children,
                 * condition);
                 * if (windowElements != null)
                 * {
                 *  foreach (AutomationElement element in windowElements)
                 *  {
                 *      elementList.Add(element);
                 *  }
                 * }
                 * else
                 * {
                 *  _Logger.WriteLog(LogTypeEnum.Debug, () => "Cannot locate object:\r\n" + UIAUtility.DumpTestObject(testObject));
                 * }*/

                goto ConditionLocatorEnd;
            }

            AutomationElementCollection matchedElements = null;

            AutomationElement parentElement = parentTestObject.AutomationElement;

            if (parentElement == null)
            {
                //TODO, refine log
                _Logger.WriteWarning("Cannot identify the parent object");
                goto ConditionLocatorEnd;
            }

            matchedElements = UIAUtility.FindDescendantElements(parentTestObject.AutomationElement, condition);

            elementList.Capacity = matchedElements.Count;
            foreach (AutomationElement element in matchedElements)
            {
                elementList.Add(element);
            }

ConditionLocatorEnd:
            _Logger.WriteDebug("ConditionLocator end");
            _Logger.WriteDebug("ConditionLocator returns count:" + elementList.Count);
            return(elementList);
        }