Description of GetControlCmdletBase.
Inheritance: GetCmdletBase
        private void getAndConditions(string name, string automationId, string className, string controlType)
        {
            ResultAndCondition = null;
            
            var cmdlet =
                new GetControlCmdletBase {Name = name, AutomationId = automationId, Class = className, CaseSensitive = false };

            var common =
                new CommonCmdletBase();
            
            // 20131128
            //ResultAndCondition =
            //    (common.GetControlConditionsForWildcardSearch(cmdlet, controlType, cmdlet.CaseSensitive, true) as AndCondition);
            // 20131129
            // ResultAndCondition =
            //     (common.GetControlConditionsForWildcardSearch(cmdlet, controlType, cmdlet.CaseSensitive));
            ResultAndCondition =
                // common.GetWildcardSearchCondition(cmdlet) as AndCondition;
                ControlSearcher.GetWildcardSearchCondition(
                    new ControlSearcherData {
                        Name = name,
                        AutomationId = automationId,
                        Class = className,
                        CaseSensitive = false
                    }) as AndCondition;
        }
        private GetControlCmdletBase GetInputCmdlet(bool empty)
        {
            var cmdlet =
                new GetControlCmdletBase {Win32 = false, Regex = false};

            cmdlet.InputObject = empty ? GetCmdletInputObject_Empty() : GetCmdletInputObject_Three();
            
            return cmdlet;
        }
 private ControlSearcher PerformGetElements(GetControlCmdletBase cmdlet)
 {
     var controlSearcher =
         AutomationFactory.GetSearcherImpl<ControlSearcher>() as ControlSearcher;
     
     controlSearcher.GetElements(
         controlSearcher.ConvertCmdletToControlSearcherData(cmdlet),
         0);
     
     return controlSearcher;
 }
        private void getOrConditions(string searchString, string controlType)
        {
            ResultOrCondition = null;
            
            GetControlCmdletBase cmdlet =
                new GetControlCmdletBase {ContainsText = searchString };

            CommonCmdletBase common =
                new CommonCmdletBase();
            
            // 20131129
            // ResultOrCondition =
            //     (common.GetControlConditionsForExactSearch(cmdlet, controlType, cmdlet.CaseSensitive, false) as OrCondition);
            ResultOrCondition =
                // common.GetTextSearchCondition(searchString, new string[] { controlType }, cmdlet.CaseSensitive) as OrCondition;
                ControlSearcher.GetTextSearchCondition(searchString, new string[] { controlType }, cmdlet.CaseSensitive) as OrCondition;
        }
 private void checkConditionsArray(
     string controlType,
     string controlTypeProperty,
     string controlTypeValue)
 {
     Condition[] conditions = null;
     cmdlet = 
         new UIAutomation.Commands.GetUiaControlCommand();
     cmdletBase = 
         new GetControlCmdletBase();
     
     Condition condition =
         // cmdlet.GetWildcardSearchCondition(cmdlet);
         ControlSearcher.GetWildcardSearchCondition(
             new ControlSearcherData {
                 // completely new
                 Name = cmdlet.Name,
                 AutomationId = cmdlet.AutomationId,
                 Class = cmdlet.Class,
                 Value = cmdlet.Value,
                 ControlType = cmdlet.ControlType
             });
     // 20140630
     // conditions = ((AndCondition)condition).GetConditions();
     if (null != condition as AndCondition) {
         conditions = ((AndCondition)condition).GetConditions();
     } else if (null != condition as OrCondition) {
         conditions = ((OrCondition)condition).GetConditions();
     } else {
         conditions = new[] { condition };
     }
     
     foreach (Condition cond in conditions) {
         if ((cond as PropertyCondition) != null) {
             MbUnit.Framework.Assert.AreEqual(
                 controlTypeProperty, 
                 (cond as PropertyCondition).Property.ProgrammaticName);
             MbUnit.Framework.Assert.AreEqual(
                 controlTypeValue, 
                 (cond as PropertyCondition).Value.ToString());
         } else {
             MbUnit.Framework.Assert.AreEqual(cond, Condition.TrueCondition);
         }
     }
 }
示例#6
0
        public ControlSearcherData ConvertCmdletToControlSearcherData(GetControlCmdletBase cmdlet)
        {
            var ControlSearcherData =
                new ControlSearcherData {
                InputObject    = cmdlet.InputObject,
                ContainsText   = cmdlet.ContainsText,
                Name           = cmdlet.Name,
                AutomationId   = cmdlet.AutomationId,
                Class          = cmdlet.Class,
                Value          = cmdlet.Value,
                ControlType    = cmdlet.ControlType,
                Regex          = cmdlet.Regex,
                CaseSensitive  = cmdlet.CaseSensitive,
                Win32          = cmdlet.Win32,
                SearchCriteria = cmdlet.SearchCriteria
            };

            return(ControlSearcherData);
        }
        protected internal bool TestControlByPropertiesFromHashtable(
            // 20130315
            AutomationElement[] inputElements,
            System.Collections.Hashtable[] SearchCriteria,
            int timeout)
        {
            bool result = false;
            for (int i = 0; i < SearchCriteria.Length; i++) {

                // 20120917
            //                string className = string.Empty;
            //                string controlType = string.Empty;
            //                string name = string.Empty;
            //                string automationId = string.Empty;

                // 20120917
                // 20130318
                //System.Collections.Generic.Dictionary<string, string> dict =
                //    this.ConvertHashtableToDictionary(SearchCriteria[i]);
                System.Collections.Generic.Dictionary<string, object> dict =
                    this.ConvertHashtableToDictionary(SearchCriteria[i]);

            //                foreach(System.Collections.Generic.KeyValuePair<string, string> entry in dict) {
            //                    this.WriteVerbose(this, entry.Key);
            //                    this.WriteVerbose(this, entry.Value);
            //                }

                // 20120917

                GetControlCmdletBase cmdlet =
                    new GetControlCmdletBase();

                // 20120917
            //                cmdlet.Class = className;
            //                cmdlet.AutomationId = automationId;
            //                cmdlet.ControlType = controlType;
            //                cmdlet.Name = name;

                // 20120917
                // 20130318
                //try{ cmdlet.Class = dict["CLASS"]; } catch {}
                try{ cmdlet.Class = dict["CLASS"].ToString(); } catch {}
                // 20130318
                //try{ cmdlet.AutomationId = dict["AUTOMATIONID"]; } catch {}
                try{ cmdlet.AutomationId = dict["AUTOMATIONID"].ToString(); } catch {}
                // 20130318
                //try{ cmdlet.ControlType = dict["CONTROLTYPE"]; } catch {}
                try{ cmdlet.ControlType = dict["CONTROLTYPE"].ToString(); } catch {}
                // 20130318
                //try{ cmdlet.Name = dict["NAME"]; } catch {}
                try{ cmdlet.Name = dict["NAME"].ToString(); } catch {}
                // 20130315
                // 20130318
                //try{ cmdlet.Value = dict["VALUE"]; } catch {}
                try{ cmdlet.Value = dict["VALUE"].ToString(); } catch {}

            //                this.WriteVerbose(this, cmdlet.Name);

                cmdlet.Timeout = timeout;

                // 20130315
                if (null != inputElements && null != (inputElements as AutomationElement[]) && 0 < inputElements.Length) {
                    cmdlet.InputObject = inputElements;
                } else {
                    if (UIAutomation.CurrentData.CurrentWindow == null) {
                    // WriteVerbose(this, " ==  == <<<<<<<<<<<<<<<<<!!!!!!!!!!!!!!!!!!!!!!  UIAutomation.CurrentData.CurrentWindow == null  !!!!!!!!!!!!! >  >  >  >  >  >  >  >  >  >  >  ==  ==  ==  ==  == =");
                    // WriteVerbose(this, "exiting");
                        return result;
                    }
                    // 20120824
                    //cmdlet.InputObject = UIAutomation.CurrentData.CurrentWindow;
                    // 20130315
                    //cmdlet.InputObject[0] = UIAutomation.CurrentData.CurrentWindow;
                    cmdlet.InputObject = new AutomationElement[]{ UIAutomation.CurrentData.CurrentWindow };
                }
                //cmdlet._window = //UIAutomation.CurrentData.CurrentWindow;
                // (System.Windows.Automation.AutomationElement)(cmdlet.InputObject);
                //AutomationElement elementToWorkWith = getControl(this);
                WriteVerbose(this, "getting the control");
                // 20120824
                //AutomationElement elementToWorkWith = getControl(cmdlet);
                //AutomationElementCollection elementsToWorkWith = getControl(cmdlet);
                // 20120824
                ArrayList elementsToWorkWith = GetControl(cmdlet);
                // 20120824
                //if (elementToWorkWith == null) {
                if (null == elementsToWorkWith) {

                    WriteVerbose(this, "couldn't get the control(s)");
                    //WriteObject(this, false);
                    return result;
                } else {

                    // 20120824
                    foreach (AutomationElement elementToWorkWith in elementsToWorkWith) {

                    WriteVerbose(this, "found the control:");
                    try {WriteVerbose(this, "Name = " + elementToWorkWith.Current.Name); }catch {}
                    try {WriteVerbose(this, "AutomationId = " + elementToWorkWith.Current.AutomationId); }catch {}
                    try {WriteVerbose(this, "ClassName = " + elementToWorkWith.Current.ClassName); }catch {}
                    try {WriteVerbose(this, "ControlType = " + elementToWorkWith.Current.ControlType.ProgrammaticName); }catch {}

                    // 20120917
                    result = testControlByPropertiesFromDictionary(dict, elementToWorkWith);
                    if (! result) {
                        return result;
                    }

            // 20120917

                    } // 20120824
                }
            }
            //WriteObject(this, true);

            // 20120917
            //result = true;
            return result;
        }
示例#8
0
        protected ArrayList getControl(GetControlCmdletBase cmdlet)
        {
            try {

                aeCtrl = new ArrayList();
                System.Windows.Automation.AndCondition conditions = null;
                // 20130221
                System.Windows.Automation.AndCondition conditionsForWildCards = null;
                // 20130221
                System.Windows.Automation.AndCondition conditionsForTextSearch = null;
                // 20130221
                //conditions = this.getControlConditions(cmdlet, cmdlet.ControlType, ((GetControlCmdletBase)cmdlet).CaseSensitive, true) as AndCondition;

                // 20130221
            //                // display conditions for a regular search
            //                this.WriteVerbose(cmdlet, "these conditions are used for an exact search:");
            //                displayConditions(cmdlet, conditions, "for exact search");

                // additional search conditions if the search works with wildcards
                // only ControlType is here since that
                // Name, AutomationID, ClassName can be wildcarded

                // 20120918
                //                System.Windows.Automation.ControlType ctrlTypeForWildCards =
                //                    UIAHelper.GetControlTypeByTypeName(cmdlet.ControlType);
                GetControlCmdletBase tempCmdlet =
                    new GetControlCmdletBase();
                tempCmdlet.ControlType = cmdlet.ControlType;
                // 20130128
                bool notTextSearch = true;
                if (null != cmdlet.ContainsText && string.Empty != cmdlet.ContainsText) {
                    tempCmdlet.ContainsText = cmdlet.ContainsText;
                    notTextSearch = false;

                    // 20130221
                    conditionsForTextSearch =
                        this.getControlConditions(
                            tempCmdlet,
                            tempCmdlet.ControlType,
                            cmdlet.CaseSensitive,
                            false) as AndCondition;

                    // display conditions for text search
                    this.WriteVerbose(cmdlet, "these conditions are used for text search:");
                    displayConditions(cmdlet, conditionsForTextSearch, "for text search");

                } else {
                    // 20130221
                    conditions = this.getControlConditions(cmdlet, cmdlet.ControlType, ((GetControlCmdletBase)cmdlet).CaseSensitive, true) as AndCondition;
                    // display conditions for a regular search
                    this.WriteVerbose(cmdlet, "these conditions are used for an exact search:");
                    displayConditions(cmdlet, conditions, "for exact search");

                    conditionsForWildCards =
                        this.getControlConditions(tempCmdlet, tempCmdlet.ControlType, ((GetControlCmdletBase)cmdlet).CaseSensitive, true) as AndCondition;

                    // display conditions for wildcard search
                    this.WriteVerbose(cmdlet, "these conditions are used for wildcard search:");
                    displayConditions(cmdlet, conditionsForWildCards, "for wildcard search");
                }
                // 20130221
                //System.Windows.Automation.AndCondition conditionsForWildCards =
                //    this.getControlConditions(tempCmdlet, tempCmdlet.ControlType, ((GetControlCmdletBase)cmdlet).CaseSensitive, true) as AndCondition;

                // 20130221
                //System.Windows.Automation.AndCondition conditionsForTextSearch =
                //    this.getControlConditions(
                //        tempCmdlet,
                //        tempCmdlet.ControlType,
                //        cmdlet.CaseSensitive,
                //        false) as AndCondition;

                // 20130221
                // // display conditions for wildcard search
                // this.WriteVerbose(cmdlet, "these conditions are used for wildcard search:");
                // displayConditions(cmdlet, conditionsForWildCards, "for wildcard search");

                // 20130221
                // // display conditions for text search
                // this.WriteVerbose(cmdlet, "these conditions are used for text search:");
                // displayConditions(cmdlet, conditionsForTextSearch, "for text search");

                // 20120823
                foreach (AutomationElement inputObject in cmdlet.InputObject) {

                    int processId = 0;
                    do {

                        if (inputObject != null &&
                            (int)inputObject.Current.ProcessId > 0) {
                            this.WriteVerbose(cmdlet, "CommonCmdletBase: getControl(cmdlet)");
                            this.WriteVerbose(cmdlet, "cmdlet.InputObject != null");

                            processId = inputObject.Current.ProcessId;

                        }
                        // 20130204
                        // don't change the order! (text->exact->wildcard->win32 to win32->text->exact->wildcard)

                        #region text search
                        if (0 == aeCtrl.Count) {
                            if (!notTextSearch && !cmdlet.Win32) {

                                SearchByTextViaUIA(cmdlet, inputObject, conditionsForTextSearch);
                            }
                        }
                        #endregion text search

                        #region text search Win32
                        if (0 == aeCtrl.Count) {
                            if (!notTextSearch && cmdlet.Win32) {

                                SearchByTextViaWin32(cmdlet, inputObject, cmdlet.ControlType);
                            }
                        }
                        #endregion text search Win32

                        #region exact search
                        if (0 == aeCtrl.Count && notTextSearch) {
                            if (!Preferences.DisableExactSearch && !cmdlet.Win32 ) {

                                SearchByExactConditionsViaUIA(cmdlet, inputObject, conditions);

                            }
                        }
                        #endregion exact search

                        #region wildcard search
                        if (0 == aeCtrl.Count && notTextSearch) {
                            if (!Preferences.DisableWildCardSearch && !cmdlet.Win32) {

                                //SearchByWildcardViaUIA(cmdlet, inputObject, conditionsForWildCards);
                                SearchByWildcardViaUIA(cmdlet, ref aeCtrl, inputObject, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class, cmdlet.Value, conditionsForWildCards);
                            }
                        }
                        #endregion wildcard search

                        #region Win32 search
                        if (0 == aeCtrl.Count && notTextSearch) { // &&
                            //(null == cmdlet.AutomationId || string.Empty == cmdlet.AutomationId) &&
                            //(null == cmdlet.Class || string.Empty == cmdlet.Class)) {

                            if (!Preferences.DisableWin32Search || cmdlet.Win32) {

                                SearchByWildcardViaWin32(cmdlet, inputObject);

                            } // if (! Preferences.DisableWin32Search)
                        } // FindWindowEx
                        #endregion Win32 search

                        if (null != aeCtrl && aeCtrl.Count > 0) {

                            break;
                        }

                        cmdlet.WriteVerbose(cmdlet, "going to sleep 99999999999");

                        SleepAndRunScriptBlocks(cmdlet);

                        // System.Threading.Thread.Sleep(Preferences.SleepInterval);
                        ////impossible due to inheritance and the absense of scriptblock here
                        // SleepAndRunScriptBlocks(cmdlet);
                        System.DateTime nowDate = System.DateTime.Now;

                        try {
                            WriteVerbose(cmdlet, "control type: '" +
                                         cmdlet.ControlType +
                                         "' , name: '" +
                                         cmdlet.Name +
                                         "', automationId: '" +
                                         cmdlet.AutomationId +
                                         "', class: '" +
                                         cmdlet.Class +
                                         "' , value: '" +
                                         cmdlet.Value +
                                         "' , seconds: " +
                                         ((nowDate - startDate).TotalSeconds).ToString());
                        } catch { //(Exception eWriteVerbose) {
                            //WriteVerbose(this, eWriteVerbose.Message);
                        }

                        if ((nowDate - startDate).TotalSeconds > cmdlet.Timeout / 1000) {

                            if (null == aeCtrl || 0 == aeCtrl.Count) {

                                return null;
                            }
                            break;
                        }
                        else{

                            rootElement =
                                System.Windows.Automation.AutomationElement.RootElement;
                            if (processId > 0) {
                                try {
                                    System.Windows.Automation.PropertyCondition pIDcondition =
                                        new System.Windows.Automation.PropertyCondition(
                                            System.Windows.Automation.AutomationElement.ProcessIdProperty,
                                            processId);
                                    AutomationElement tempElement =
                                        rootElement.FindFirst(System.Windows.Automation.TreeScope.Children,
                                                              pIDcondition);
                                    if (tempElement != null &&
                                        (int)tempElement.Current.ProcessId > 0) {
                                    } else {

                                        // 20120830 (the new style of writing errors)
                                        this.WriteError(
                                            cmdlet,
                                            "The input control or window has been lost",
                                            "ObjectOrWindowLost",
                                            ErrorCategory.ObjectNotFound,
                                            true);

                                        return null;
                                    }
                                } catch {//"process is gone"
                                    // get new window

                                }
                            } else {
                                this.WriteVerbose(cmdlet, "failed to get the process Id");
                                // 20120830
                                //return null;
                                // 20120830 (the new style of writing errors)
                                this.WriteError(
                                    cmdlet,
                                    "The input control or window has been lost",
                                    "ObjectOrWindowLost",
                                    ErrorCategory.ObjectNotFound,
                                    true);

                                return null;
                            } //#describe the output
                        }

                        //} // 20120823
                    } while (cmdlet.Wait);

                } // 20120823

                #region commented
                // 20120824
                //if (aeCtrl != null && (int)aeCtrl.Current.ProcessId > 0)
                // 20120830
                //if (null != aeCtrl && (int)((AutomationElement)aeCtrl[0]).Current.ProcessId > 0) {
                //{
                //                if (null != aeCtrl && 0 < aeCtrl.Count) {
                //                    WriteVerbose(cmdlet, aeCtrl);
                //                }
            //
            //
                //                // 20120917
                //                if (null == aeCtrl) {
                //                    cmdlet.WriteVerbose(cmdlet, "aeCtrl == null");
                //                }
                //                if (0 == aeCtrl.Count) {
                //                    cmdlet.WriteVerbose(cmdlet, "aeCtrl.Count == 0");
                //                }
                #endregion commented

                return aeCtrl;
                #region commented
            }
            catch (Exception eGetControlException) {

                this.WriteError(
                    cmdlet,
                    "Failed to get the control." +
                    eGetControlException.Message,
                    "UnableToGetControl",
                    ErrorCategory.InvalidResult,
                    true);

                return null;
            }
            //            catch {
            //                this.WriteError(
            //                    cmdlet,
            //                    "Failed to get the control.",
            //                    "UnableToGetControl",
            //                    ErrorCategory.InvalidResult,
            //                    true);
            //
            //                return null;
            //            }
            #endregion commented
        }
示例#9
0
 public ControlSearcherData ConvertCmdletToControlSearcherData(GetControlCmdletBase cmdlet)
 {
     var ControlSearcherData =
         new ControlSearcherData {
         InputObject = cmdlet.InputObject,
         ContainsText = cmdlet.ContainsText,
         Name = cmdlet.Name,
         AutomationId = cmdlet.AutomationId,
         Class = cmdlet.Class,
         Value = cmdlet.Value,
         ControlType = cmdlet.ControlType,
         Regex = cmdlet.Regex,
         CaseSensitive = cmdlet.CaseSensitive,
         Win32 = cmdlet.Win32,
         SearchCriteria = cmdlet.SearchCriteria
     };
     
     return ControlSearcherData;
 }
示例#10
0
 internal void SearchByWildcardViaWin32(GetControlCmdletBase cmdlet, AutomationElement inputObject)
 {
     this.WriteVerbose(cmdlet, "[getting the control] using FindWindowEx");
     ArrayList tempListWin32 = new ArrayList();
     if (null != cmdlet.Name && string.Empty != cmdlet.Name) {
         this.WriteVerbose(cmdlet, "collecting controls by name (Win32)");
         tempListWin32.AddRange(UIAHelper.GetControlByName(cmdlet, inputObject, cmdlet.Name));
     }
     if (null != cmdlet.Value && string.Empty != cmdlet.Value) {
         this.WriteVerbose(cmdlet, "collecting controls by value (Win32)");
         tempListWin32.AddRange(UIAHelper.GetControlByName(cmdlet, inputObject, cmdlet.Value));
     }
     foreach (AutomationElement tempElement3 in tempListWin32) {
         if (null != cmdlet.ControlType && 0 < cmdlet.ControlType.Length) {
             if (!tempElement3.Current.ControlType.ProgrammaticName.ToUpper().Contains(cmdlet.ControlType.ToUpper()) ||
                 !(tempElement3.Current.ControlType.ProgrammaticName.ToUpper().Substring(12).Length == cmdlet.ControlType.ToUpper().Length)) {
                 continue;
             }
         }
         if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
             aeCtrl.Add(tempElement3);
             cmdlet.WriteVerbose(cmdlet, "Win32Search: element added to the result collection");
         } else {
             cmdlet.WriteVerbose(cmdlet, "Win32Search: checking search criteria");
             if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement3)) {
                 cmdlet.WriteVerbose(cmdlet, "Win32Search: the control matches the search criteria");
                 aeCtrl.Add(tempElement3);
                 cmdlet.WriteVerbose(cmdlet, "Win32Search: element added to the result collection");
             }
         }
     }
 }
示例#11
0
        protected void displayConditions(
            GetControlCmdletBase cmdlet,
            AndCondition conditions,
            string description)
        {
            try {
                Condition[] conds = conditions.GetConditions();
                for (int i = 0; i < conds.Length; i++) {
                    cmdlet.WriteVerbose(cmdlet, "<<<< displaying conditions '" + description + "' >>>>");
                    cmdlet.WriteVerbose(cmdlet, (conds[i] as PropertyCondition).Property.ProgrammaticName);
                    cmdlet.WriteVerbose(cmdlet, (conds[i] as PropertyCondition).Value.ToString());
                    cmdlet.WriteVerbose(cmdlet, (conds[i] as PropertyCondition).Flags.ToString());

                }
            }
            catch {}
        }
示例#12
0
 internal void SearchByTextViaUIA(
     GetControlCmdletBase cmdlet,
     AutomationElement inputObject,
     System.Windows.Automation.AndCondition conditionsForTextSearch)
 {
     this.WriteVerbose(cmdlet, "Text search");
     AutomationElementCollection textSearchCollection = inputObject.FindAll(TreeScope.Descendants, conditionsForTextSearch);
     if (null != textSearchCollection && 0 < textSearchCollection.Count) {
         this.WriteVerbose(cmdlet, "There are " + textSearchCollection.Count.ToString() + " elements");
         foreach (AutomationElement element in textSearchCollection) {
             aeCtrl.Add(element);
         }
     }
 }
示例#13
0
        internal void SearchByTextViaWin32(
            GetControlCmdletBase cmdlet,
            AutomationElement inputObject,
            string controlType)
        {
            this.WriteVerbose(cmdlet, "Text search Win32");
            ArrayList textSearchWin32List =
                UIAHelper.GetControlByName(
                    cmdlet,
                    inputObject,
                    cmdlet.ContainsText);

            if (null != textSearchWin32List && 0 < textSearchWin32List.Count) {

                this.WriteVerbose(cmdlet, "There are " + textSearchWin32List.Count.ToString() + " elements");
                foreach (AutomationElement elementToChoose in textSearchWin32List) {

                    if (null != controlType && string.Empty != controlType && 0 < controlType.Length) {

                        if (!elementToChoose.Current.ControlType.ProgrammaticName.ToUpper().Contains(controlType.ToUpper()) ||
                            !(elementToChoose.Current.ControlType.ProgrammaticName.ToUpper().Substring(12).Length == controlType.ToUpper().Length)) {

                            continue;
                        } else {

                            aeCtrl.Add(elementToChoose);
                        }
                    } else {

                        aeCtrl.Add(elementToChoose);
                    }
                }
            }
        }
示例#14
0
        internal void SearchByWildcardViaUIA(
            //GetCmdletBase cmdlet,
            GetControlCmdletBase cmdlet, // 20130318 // ??
            ref ArrayList resultCollection,
            AutomationElement inputObject,
            string name,
            string automationId,
            string className,
            string strValue,
            System.Windows.Automation.AndCondition conditionsForWildCards)
        {
            this.WriteVerbose((cmdlet as PSTestLib.PSCmdletBase), "[getting the control] using WildCard search");
            try {

                // 20130220
                GetControlCollectionCmdletBase cmdlet1 =
                    new GetControlCollectionCmdletBase(
                        //cmdlet.InputObject,
                        null != cmdlet.InputObject ? cmdlet.InputObject : (new AutomationElement[]{ AutomationElement.RootElement }),
                        //null,
                        name, //cmdlet.Name,
                        automationId, //cmdlet.AutomationId,
                        className, //cmdlet.Class,
                        //cmdlet.Value,
                        //string.Empty != cmdlet.Value ? cmdlet.Value : null,
                        strValue,
                        // 20130318
                        //(new string[] {}),
                        //null != cmdlet.controlt
                        //string.Empty != cmdlet.ControlType ? cmdlet.ControlType : (new string[] {}),
                        //null != cmdlet.ControlType ? cmdlet.ControlType : (new string[] {}),
                        //null != cmdlet.ControlType ? cmdlet.ControlType : string.Empty,
                        //string.Empty != cmdlet.ControlType ? cmdlet.ControlType : string.Empty,
                        null != cmdlet.ControlType ? (new string[] {cmdlet.ControlType}) : (new string[] {}),
                        this.caseSensitive);

                try {
                    this.WriteVerbose((cmdlet as PSTestLib.PSCmdletBase), "using the GetAutomationElementsViaWildcards_FindAll method");

                    ArrayList tempList =
                        cmdlet1.GetAutomationElementsViaWildcards_FindAll(
                            cmdlet1,
                            inputObject,
                            conditionsForWildCards,
                            cmdlet1.CaseSensitive,
                            false,
                            false);

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "there are " +
                        tempList.Count.ToString() +
                        " elements that match the conditions");

                    foreach (AutomationElement tempElement2 in tempList) {

                        if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {

                            resultCollection.Add(tempElement2);
                            cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (no SearchCriteria)");
                        } else {

                            cmdlet.WriteVerbose(cmdlet, "WildCardSearch: checking search criteria");
                            if (TestControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement2)) {

                                cmdlet.WriteVerbose(cmdlet, "WildCardSearch: the control matches the search criteria");
                                resultCollection.Add(tempElement2);
                                cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria)");
                            }
                            // cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria) (2)");
                        }
                        // cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria) (3)");
                    }
                    cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element(s) added to the result collection: " + resultCollection.Count.ToString());
                } catch (Exception eUnexpected) {

                    // this.WriteVerbose(this, eUnexpected.Message);
                    this.WriteError(
                        this,
                        "The input control or window has been possibly lost." +
                        eUnexpected.Message,
                        "UnexpectedError",
                        ErrorCategory.ObjectNotFound,
                        true);
                }
            } catch (Exception eWildCardSearch) {

                this.WriteError(
                    cmdlet,
                    "The input control or window has been possibly lost." +
                    eWildCardSearch.Message,
                    "UnexpectedError",
                    ErrorCategory.ObjectNotFound,
                    true);
            }
        }
示例#15
0
        internal void SearchByExactConditionsViaUIA(
            GetControlCmdletBase cmdlet,
            AutomationElement inputObject,
            System.Windows.Automation.AndCondition conditions)
        {
            #region the -First story
            // 20120824
            //aeCtrl =
            // 20120921
            #region -First
            //                                    if (cmdlet.First) {
            //                                        AutomationElement tempFirstElement =
            //                                            inputObject.FindFirst(
            //                                                System.Windows.Automation.TreeScope.Descendants,
            //                                                conditions);
            //                                        if (null != tempFirstElement) {
            //                                            if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
            //                                                aeCtrl.Add(tempFirstElement);
            //                                            } else {
            //                                                if (testControlWithAllSearchCriteria(
            //                                                    cmdlet,
            //                                                    cmdlet.SearchCriteria,
            //                                                    tempFirstElement)) {
            //                                                    aeCtrl.Add(tempFirstElement);
            //                                                }
            //                                            }
            //                                        }
            //                                    } else {
            #endregion -First
            // 20120823
            //cmdlet.InputObject.FindFirst(System.Windows.Automation.TreeScope.Descendants,

            // 20120824
            // 20120917
            #region -First
            //                                    }
            #endregion -First
            //else if (UIAutomation.CurrentData.LastResult
            #endregion the -First story

            //internal void SearchByExactConditionsViaUIA(System.Windows.Automation.AndCondition conditions, ref bool notTextSearch, ref System.Windows.Automation.AndCondition conditionsForWildCards, ref AutomationElement inputObject, ref int processId, GetControlCmdletBase cmdlet)
            //{

            if (conditions != null) {
                if (inputObject != null && (int)inputObject.Current.ProcessId > 0) {
                    AutomationElementCollection tempCollection = inputObject.FindAll(System.Windows.Automation.TreeScope.Descendants, conditions);
                    foreach (AutomationElement tempElement in tempCollection) {
                        if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
                            aeCtrl.Add(tempElement);
                            cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
                        } else {
                            cmdlet.WriteVerbose(cmdlet, "ExactSearch: checking search criteria");
                            if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement)) {
                                cmdlet.WriteVerbose(cmdlet, "ExactSearch: the control matches the search criteria");
                                aeCtrl.Add(tempElement);
                                cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
                            }
                        }
                    }
                }
            }
        }
示例#16
0
        internal ArrayList GetWindow(
            GetWindowCmdletBase cmdlet,
            // 20130513
            bool win32,
            Process[] processes,
            string[] processNames,
            int[] processIds,
            string[] windowNames,
            string automationId,
            string className,
            bool testMode)
        {
            ArrayList aeWndCollection =
                new ArrayList();

            cmdlet.WriteVerbose(cmdlet, "getting the root element");
            rootElement =
                System.Windows.Automation.AutomationElement.RootElement;
            if (rootElement == null)
            {
                cmdlet.WriteVerbose(cmdlet, "rootElement == null");
                return aeWndCollection;
            }
            else
            {
                cmdlet.WriteVerbose(cmdlet, "rootElement: " + rootElement.Current);
            }

            // 20130529
            bool wasFound = false;
            do {

                // 20130513
                //if (null != processes && processes.Length > 0) {
                if (win32) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window via Win32 API");
                    aeWndCollection = getWindowCollectionViaWin32(cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if (null != processes && processes.Length > 0) {
                    cmdlet.WriteVerbose(cmdlet, "getting a window by process");
                    aeWndCollection = getWindowCollectionFromProcess(processes, cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if (null != processIds && processIds.Length > 0) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window by PID");
                    aeWndCollection = getWindowCollectionByPID(processIds, cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if (null != processNames && processNames.Length > 0) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window by name");
                    aeWndCollection = getWindowCollectionByProcessName(processNames, cmdlet.First, cmdlet.Recurse, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class);

                } else if ((null != windowNames && windowNames.Length > 0) ||
                           (null != automationId && 0 < automationId.Length) ||
                           (null != className && 0 < className.Length)) {

                    cmdlet.WriteVerbose(cmdlet, "getting a window by name, automationId, className");
                    aeWndCollection = getWindowCollectionByName(windowNames, automationId, className, cmdlet.Recurse);
                }

                // 20130228
                // filtering result window collection by SearchCriteria
                if (null != aeWndCollection && 0 < aeWndCollection.Count) {

                    cmdlet.WriteVerbose(cmdlet, "one or several windows were found by name, process name, process id or process object");

                    if (null != cmdlet.SearchCriteria && 0 < cmdlet.SearchCriteria.Length) {

                        cmdlet.WriteVerbose(cmdlet, "processing SearchCriteria");

                        aeWndCollection =
                            cmdlet.getFiltredElementsCollection(
                                cmdlet,
                                aeWndCollection);
                    }
                }

                // filtering result window collection by having a control(s) with properties as from WithControl
                if (null != aeWndCollection && 0 < aeWndCollection.Count) {

                    cmdlet.WriteVerbose(cmdlet, "one or several windows were not excluded by SearchCriteria");

                    if (null != cmdlet.WithControl && 0 < cmdlet.WithControl.Length) {

                        cmdlet.WriteVerbose(cmdlet, "processing WithControl");

                        ArrayList filteredWindows =
                            new ArrayList();

                        foreach (AutomationElement window in aeWndCollection) {

                            cmdlet.WriteVerbose(cmdlet, "searching for control(s) for every window, one by one");

                            GetControlCmdletBase cmdletCtrl =
                                new GetControlCmdletBase();
                            //cmdletCtrl.InputObject = (AutomationElement[])aeWndCollection.ToArray();
                            cmdletCtrl.InputObject =
                                // 20130316
                                //(AutomationElement[])aeWndCollection.ToArray(typeof(AutomationElement));
                                new AutomationElement[]{ window };
                            cmdletCtrl.SearchCriteria = cmdlet.WithControl;
                            cmdletCtrl.Timeout = 0;

                            cmdlet.WriteVerbose(cmdlet, "searching for one or more controls");

                            // 20130301
                            try {

                                ArrayList controlsList =
                                    GetControl(cmdletCtrl);

                                cmdlet.WriteVerbose(cmdlet, "after the search");

                                if (null != controlsList && 0 < controlsList.Count) {

                                    cmdlet.WriteVerbose(cmdlet, "ths list of controls that are on the window is not empty");

                                    filteredWindows.Add(window);
                                }

                            // 20130301
                            }

                            catch (Exception eWindowIsGone) {

                                // forcing to a next loop
                                aeWndCollection.Clear();
                                break;

                            }
                        }

                        aeWndCollection = filteredWindows;
                    }
                }

                // 20130529
                if (cmdlet.WaitNoWindow && wasFound && (null == aeWndCollection || 0 == aeWndCollection.Count)) {

                    cmdlet.Wait = false;
                }

                if (cmdlet.WaitNoWindow && !wasFound && null != aeWndCollection && 0 != aeWndCollection.Count) {

                    wasFound = true;
                    aeWndCollection = null;
                }

                if (null != aeWndCollection && aeWndCollection.Count > 0) {

                    cmdlet.WriteVerbose(cmdlet, "aeWndCollection != null");

                }
                // 20120123
                // checkTimeout(ref aeWnd, true);
                // 20120824
                //checkTimeout(cmdlet, aeWnd, true);
                checkTimeout(cmdlet, aeWndCollection, true);

                System.Threading.Thread.Sleep(Preferences.OnSleepDelay);

            } while (cmdlet.Wait);
            try {

                if (null != aeWndCollection && (int)((AutomationElement)aeWndCollection[0]).Current.ProcessId > 0) {

                    cmdlet.WriteVerbose(cmdlet, "" + aeWndCollection.ToString());
                    cmdlet.WriteVerbose(cmdlet,
                                        "aeWnd.Current.GetType() = " +
                                        ((AutomationElement)aeWndCollection[0]).GetType().Name);

                } // 20120127

                CurrentData.CurrentWindow = (AutomationElement)aeWndCollection[aeWndCollection.Count -1];
                // 20120824
                //return aeWnd;
                //return aeWndCollection;
            } catch (Exception eEvaluatingWindowAndWritingToPipeline) {

                //WriteDebug(cmdlet, "exception: " +
                cmdlet.WriteVerbose(
                    cmdlet,
                    "exception: " +
                    eEvaluatingWindowAndWritingToPipeline.Message);

                cmdlet.WriteVerbose(this, "<<<< ==  ==  writing/nullifying CurrentWindow  ==  == >>>>>");

                CurrentData.CurrentWindow = null;

            }

            return aeWndCollection;
        }
        private void getConditions(string name, string automationId, string className, string controlType)
        {
            this.ResultCondition = null;

            GetControlCmdletBase cmdlet =
                new GetControlCmdletBase();
            cmdlet.Name = name;
            cmdlet.AutomationId = automationId;
            cmdlet.Class = className;

            UIAutomation.CommonCmdletBase common =
                new UIAutomation.CommonCmdletBase();

            this.ResultCondition =
                (common.getControlConditions(cmdlet, controlType, cmdlet.CaseSensitive, true) as AndCondition);
        }
 public void DisposeRunspace()
 {
     // MiddleLevelCode.DisposeRunspace();
     cmdlet = null;
 }
 private void checkConditionsArray(
     string controlType,
     string controlTypeProperty,
     string controlTypeValue)
 {
     Condition[] conditions = null;
     cmdlet =
         new UIAutomation.Commands.GetUIAControlCommand();
     cmdletBase =
         // 20130221
         // new UIAutomation.CommonCmdletBase();
         new UIAutomation.GetControlCmdletBase();
     AndCondition condition =
         // 20130127
         //cmdlet.getControlConditions(cmdlet, controlType);
         // 20130128
         //cmdlet.getControlConditions(cmdlet, controlType, ((GetControlCmdletBase)cmdlet).CaseSensitive);
         //cmdlet.getControlConditions(cmdlet, controlType, ((GetControlCmdletBase)cmdlet).CaseSensitive, true);
         cmdlet.getControlConditions(cmdlet, controlType, ((GetControlCmdletBase)cmdlet).CaseSensitive, true) as AndCondition;
     conditions = condition.GetConditions();
     foreach (Condition cond in conditions) {
         if ((cond as PropertyCondition) != null) {
             Assert.AreEqual(
                 controlTypeProperty,
                 (cond as PropertyCondition).Property.ProgrammaticName);
             Assert.AreEqual(
                 controlTypeValue,
                 (cond as PropertyCondition).Value.ToString());
         } else {
             Assert.AreEqual(cond, Condition.TrueCondition);
         }
     }
 }
        protected internal bool TestControlByPropertiesFromHashtable(
            IUiElement[] inputElements,
            IEnumerable<Hashtable> searchCriteria,
            int timeout)
        {
            bool result = false;
            
            if (null == searchCriteria || 0 == searchCriteria.Count()) return result;
            if (null == inputElements || 0 == inputElements.Length) return result;
            
            foreach (Hashtable ht in searchCriteria)
            {
                Dictionary<string, object> dict =
                    ht.ConvertHashtableToDictionary();
                
                var cmdlet = new GetControlCmdletBase();
                
                try { cmdlet.Class = dict["CLASS"].ToString(); } catch {}
                try { cmdlet.AutomationId = dict["AUTOMATIONID"].ToString(); } catch {}
                // 20131128
                // try{ cmdlet.ControlType = dict["CONTROLTYPE"].ToString(); } catch {}
                // 20131203
                try { cmdlet.ControlType = new string[] { dict["CONTROLTYPE"].ToString() }; } catch {}
                try { cmdlet.Name = dict["NAME"].ToString(); } catch {}
                try { cmdlet.Value = dict["VALUE"].ToString(); } catch {}
                
                cmdlet.Timeout = timeout;
                
                if (null != inputElements && null != (inputElements as IUiElement[]) && inputElements.Any()) {
                    cmdlet.InputObject = inputElements;
                } else {
                    if (CurrentData.CurrentWindow == null) {
                        return result;
                    }
                    cmdlet.InputObject = new[]{ CurrentData.CurrentWindow };
                }
                
                var controlSearcher =
                    AutomationFactory.GetSearcherImpl<ControlSearcher>() as ControlSearcher;
                
                List<IUiElement> elementsToWorkWith =
                    controlSearcher.GetElements(
                        controlSearcher.ConvertCmdletToControlSearcherData(cmdlet),
                        cmdlet.Timeout);
                
                // 20140212
                // if (null == elementsToWorkWith) {
                if (null == elementsToWorkWith || 0 == elementsToWorkWith.Count) {
//                    WriteVerbose(this, "couldn't get the control(s)");
                    return result;
                } else {
                    
                    // 20140212
                    bool theCurrentHashtableMatchesAtLeastOneElement = false;
                    
                    foreach (IUiElement elementToWorkWith in elementsToWorkWith) {
                        
                        bool oneControlResult = 
                            elementToWorkWith.TestControlByPropertiesFromDictionary(dict);
                        
                        if (oneControlResult) {
                            
                            if (Preferences.HighlightCheckedControl) {
                                UiaHelper.HighlightCheckedControl(elementToWorkWith);
                            }
                            
                            theCurrentHashtableMatchesAtLeastOneElement = true;
                            // result = true;
                            break;
                        } else { // 20130710
                            // 20140211
                            // return result;
                            // nothing to do
                        }
                    
                    } // 20120824
                    
                    if (!theCurrentHashtableMatchesAtLeastOneElement) return result;
                }
            }
            
            // 20140211
            // 20140211
            result = true;
            
            return result;
        }