Exemple #1
0
        /// <summary>
        /// after not found any element, retry search, because maybe another windows appear need to update to RuntimeInstance
        /// </summary>
        /// <param name="idAndNameCondition"></param>
        public static AutomationElement RetrySearchAutomationElementAndUpdate(IdAndNameDesignCondition idAndNameCondition)
        {
            PropertyCondition           processCondition = new PropertyCondition(AutomationElement.ProcessIdProperty, RuntimeInstance.processTesting.Id);
            AutomationElementCollection listWindows      = AutomationElement.RootElement.FindAll(TreeScope.Children, processCondition);

            RuntimeInstance.listRootAutoElement = ConvertCollection2List(listWindows);
            return(DoSearchAutomationElement(idAndNameCondition, RuntimeInstance.listRootAutoElement));
        }
Exemple #2
0
        /// <summary>
        /// search automation rootElement
        /// </summary>
        /// <param name="idAndNameCondition"></param>
        /// <returns></returns>
        public static AutomationElement SearchAutomationElement(IdAndNameDesignCondition idAndNameCondition)
        {
            List <AutomationElement> listAutoRootElement = RuntimeInstance.listRootAutoElement;

            if (listAutoRootElement == null || listAutoRootElement.Count == 0)
            {
                listAutoRootElement.Add(AutomationElement.RootElement);
            }
            return(SearchAutomationElement(idAndNameCondition, listAutoRootElement));
        }
Exemple #3
0
        public static AutomationElement SearchAutomationElement(
            IdAndNameDesignCondition idAndNameCondition, List <AutomationElement> listAutoRootElement)
        {
            var re = DoSearchAutomationElement(idAndNameCondition, listAutoRootElement);

            if (re == null)
            {
                return(RetrySearchAutomationElementAndUpdate(idAndNameCondition));
            }
            return(re);
        }
Exemple #4
0
        public static List <AutomationElement> SearchListAutomationElements(IElement element, AutomationElement rootAutoElement)
        {
            IdAndNameDesignCondition idAndNameCondition = new IdAndNameDesignCondition(element.Attributes.DesignedId, element.Attributes.DesignedName);
            Condition    idCondition   = new PropertyCondition(AutomationElement.AutomationIdProperty, idAndNameCondition.DesignId);
            Condition    nameCondition = new PropertyCondition(AutomationElement.NameProperty, idAndNameCondition.DesignName);
            AndCondition condition     = new AndCondition(idCondition, nameCondition);
            AutomationElementCollection listElements = rootAutoElement.FindAll(TreeScope.Subtree, condition);

            AutomationElement[] re = new AutomationElement[listElements.Count];
            listElements.CopyTo(re, 0);
            return(re.ToList());
        }
Exemple #5
0
 public static AutomationElement DoSearchAutomationElement(
     IdAndNameDesignCondition idAndNameCondition, List <AutomationElement> listAutoRootElement)
 {
     foreach (AutomationElement autoRootElement in listAutoRootElement)
     {
         AutomationElement re = SearchAutomationElement(idAndNameCondition, autoRootElement);
         if (re != null)
         {
             return(re);
         }
     }
     return(null);
 }
Exemple #6
0
        public static AutomationElement SearchAutomationElement(IdAndNameDesignCondition idAndNameCondition, AutomationElement rootAutoElement)
        {
            Condition    idCondition   = new PropertyCondition(AutomationElement.AutomationIdProperty, idAndNameCondition.DesignId);
            Condition    nameCondition = new PropertyCondition(AutomationElement.NameProperty, idAndNameCondition.DesignName);
            AndCondition condition     = new AndCondition(idCondition, nameCondition);
            AutomationElementCollection listElements = rootAutoElement.FindAll(TreeScope.Subtree, condition);

            if (listElements == null || listElements.Count == 0)
            {
                return(null);
            }
            if (listElements.Count > 1)
            {
                logger.Warn("More than one automation rootElement were found with Id: " + idAndNameCondition.DesignId +
                            " and Name: " + idAndNameCondition.DesignName);
            }
            // return first rootElement
            return(listElements[0]);
        }