Ejemplo n.º 1
1
        public static CondictionScript GetBaseCondiction(AutomationElement element,Window rootWindow)
        {
            var walker =
              new System.Windows.Automation.TreeWalker(
                  System.Windows.Automation.Condition.TrueCondition);

            System.Windows.Automation.AutomationElement testparent;
            var baseCondiction = new CondictionScript();
            var paths=new List<AutomationElement>();

            GetPath(element, rootWindow, walker, paths);

            int flag = AnalyseSimpleCondiction(paths, rootWindow, baseCondiction);

            if(flag>0)
            {
                return baseCondiction;
            }
            else if(flag==0)
            {
                return new CondictionScript();
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 2
0
        private static int AnalyseSimpleCondiction(List<AutomationElement> paths, Window rootWindow, CondictionScript baseCondiction)
        {
            int index = -1;
            CondictionType type;
            string parameter;
            bool findNext = false;
            var nodeWindow = rootWindow;

            if(paths.Count==0)
            {
                return -1;
            }

            do
            {
                findNext = false;
                for (int i = paths.Count-1; i > index; i--)
                {
                    int flag = CanFindWinodw(paths[i], ref nodeWindow, out type, out parameter);
                    if(flag==0)
                    {
                        return 0;
                    }
                    if (flag > 0)
                    {
                        baseCondiction.Pairs.Add(new CondictionPair() {Type = type, Paremter = parameter});
                        index = i;
                        findNext = true;
                        break;
                    }
                }

                if(!findNext&&index!=paths.Count-1)
                {
                    return -1;
                }

            } while (findNext);

            return 1;
        }
Ejemplo n.º 3
0
        private static bool IsCanFind(AutomationElement automationElement, Window baseWindow, out CondictionScript creatCondiction)
        {
            creatCondiction =new CondictionScript();
            var allTypes = Enum.GetValues(typeof(CondictionType)).Cast<CondictionType>();
            foreach (var type in allTypes)
            {
                try

                {
                    creatCondiction = CondictionFinder.CondictionScripts[type](baseWindow, automationElement);
                    if (creatCondiction != null)
                    {
                        return true;
                    }
                }
                catch (Exception)
                {

                }
            }
            return false;
        }
Ejemplo n.º 4
0
        private static bool GetAllControls(List<ControlScript> condictionScripts, CondictionScript condictionScript, Window baseWindow)
        {
            var elements = new List<AutomationElement>();
            FindMatchingDescendants(baseWindow.AutomationElement, elements,
                                    int.Parse(ConfigInstance.InstanceDic["MaxDeep"]));

            for (int i = 0; i < elements.Count; i++)
            {
                CondictionScript creatCondiction = null;
                if(IsCanFind(elements[i],baseWindow,out creatCondiction))
                {
                    var cs = new ControlScript
                        {BaseControlCondictionScrID = condictionScript.Id, CreatCondiction = creatCondiction, Index = i};

                    condictionScripts.Add(cs);
                }
            }
            return true;
        }
Ejemplo n.º 5
0
        public static bool GetControlScript(AutomationElement curElement, Window rootWindow, out CondictionScript condictionScript, out List<ControlScript> controlScripts)
        {
            controlScripts = new List<ControlScript>();
            condictionScript = BaseWindowFinder.GetBaseCondiction(curElement, rootWindow);
            Window baseWindow;

            if(condictionScript==null)
            {
                return false;
            }
            else if(condictionScript.Pairs.Count==0)
            {
                baseWindow = rootWindow;
            }
            else
            {
                baseWindow = UIControlFactory<Window, Window>.GetControl(rootWindow, condictionScript);
            }

            if(baseWindow==null)
            {
                return false;
            }

            if (GetAllControls(controlScripts, condictionScript, baseWindow))
            {
                return true;
            }
            return false;
        }