Description of GetCmdletBase.
Inheritance: HasTimeoutCmdletBase
Example #1
0
        internal void SearchByWildcardViaUIA(
            //GetControlCmdletBase cmdlet,
            //T cmdlet,
            //CommonCmdletBase cmdlet,
            //HasTimeoutCmdletBase cmdlet,
            GetCmdletBase cmdlet,
            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 {
            //                string cmdletValue = string.Empty;
            //                try {
            //                    cmdletValue = cmdlet.Value;
            //                }
            //                catch {}
                // 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,
                        (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);
            }
        }
Example #2
0
        //        protected System.Collections.Generic.Dictionary<string, string> convertHashtableToDictionary(
        //            Hashtable hashtable)
        //        {
        //            System.Collections.Generic.Dictionary<string, string> dict =
        //                new System.Collections.Generic.Dictionary<string, string>();
        //
        //            this.WriteVerbose(this, hashtable.Keys.Count.ToString());
        //
        //            foreach (string key1 in hashtable.Keys) {
        //
        //                string keyUpper = key1.ToUpper();
        //
        //                this.WriteVerbose(this, "found key: " + keyUpper);
        //
        //                dict.Add(keyUpper, hashtable[key1].ToString());
        //
        //                this.WriteVerbose(this, "added to the dictionary: " +
        //                                  keyUpper + " = " + dict[keyUpper].ToString());
        //            }
        //
        //            return dict;
        //        }
        protected bool testControlWithAllSearchCriteria(
            GetCmdletBase cmdlet,
            Hashtable[] hashtables,
            AutomationElement element)
        {
            bool result = false;

            foreach (Hashtable hashtable in hashtables) {

                //cmdlet.WriteVerbose(cmdlet, "hashtable: " + hashtable.Keys);

                result =
                    testControlByPropertiesFromDictionary(
                        this.ConvertHashtableToDictionary(hashtable),
                        element);

                if (result) {
                    return result;
                }

                //                if (! result) {
                //                    cmdlet.WriteVerbose(cmdlet, "test of the control has failed");
                //                    return result;
                //                }
                cmdlet.WriteVerbose(cmdlet, "test of the control has passed");
            }

            //result = true;
            return result;
        }
Example #3
0
        //        protected System.Collections.Generic.Dictionary<string, string> convertHashtableToDictionary(
        //            Hashtable hashtable)
        //        {
        //            System.Collections.Generic.Dictionary<string, string> dict =
        //                new System.Collections.Generic.Dictionary<string, string>();
        //
        //            this.WriteVerbose(this, hashtable.Keys.Count.ToString());
        //
        //            foreach (string key1 in hashtable.Keys) {
        //
        //                string keyUpper = key1.ToUpper();
        //
        //                this.WriteVerbose(this, "found key: " + keyUpper);
        //
        //                dict.Add(keyUpper, hashtable[key1].ToString());
        //
        //                this.WriteVerbose(this, "added to the dictionary: " +
        //                                  keyUpper + " = " + dict[keyUpper].ToString());
        //            }
        //
        //            return dict;
        //        }
        protected internal bool TestControlWithAllSearchCriteria(
            GetCmdletBase cmdlet,
            Hashtable[] hashtables,
            AutomationElement element)
        {
            bool result = false;

            foreach (Hashtable hashtable in hashtables) {

                //cmdlet.WriteVerbose(cmdlet, "hashtable: " + hashtable.Keys);

                result =
                    testControlByPropertiesFromDictionary(
                        this.ConvertHashtableToDictionary(hashtable),
                        element);

                if (result) {

                    // 20130423
                    if (Preferences.HighlightCheckedControl) {
                        UIAHelper.HighlightCheckedControl(element);
                    }

                    return result;
                }

                //                if (! result) {
                //                    cmdlet.WriteVerbose(cmdlet, "test of the control has failed");
                //                    return result;
                //                }
                //cmdlet.WriteVerbose(cmdlet, "test of the control has passed");
                cmdlet.WriteVerbose(cmdlet, "test of the control has finished");
            }

            //result = true;
            return result;
        }
Example #4
0
        public object getControlConditions(GetCmdletBase cmdlet1, string controlType, bool caseSensitive, bool AndVsOr)
        {
            System.Windows.Automation.ControlType ctrlType = null;
            System.Windows.Automation.AndCondition andConditions = null;
            // 20130128
            System.Windows.Automation.OrCondition orConditions = null;
            System.Windows.Automation.PropertyCondition condition = null;
            // 20130128
            System.Windows.Automation.AndCondition allConditions = null;
            // 20130128
            object conditionsToReturn = null;
            // 20130127
            PropertyConditionFlags flags = PropertyConditionFlags.None;
            if (!caseSensitive) {
                flags = PropertyConditionFlags.IgnoreCase;
            }

            GetControlCmdletBase cmdlet =
                // 20130220
                (GetControlCmdletBase)cmdlet1;
                //new GetControlCmdletBase();

            // 20130128
            // the TextSearch mode
            // 20130220
            //if (null != cmdlet.ContainsText &&
            if (null != (cmdlet as GetControlCmdletBase) && null != cmdlet.ContainsText &&
                // 20130220
                string.Empty != cmdlet.ContainsText &&
                !AndVsOr) {

                // 20130220
                cmdlet.Name =
                    //cmdlet.AutomationId =
                    (cmdlet as GetControlCmdletBase).AutomationId =
                    //cmdlet.Class =
                    (cmdlet as GetControlCmdletBase).Class =
                    //cmdlet.Value =
                    (cmdlet as GetControlCmdletBase).Value =
                    //cmdlet.ContainsText;
                    (cmdlet as GetControlCmdletBase).ContainsText;

            }

            //if (cmdlet.ControlType != null && cmdlet.ControlType.Length > 0) {
            if (controlType != null && controlType.Length > 0) {

                WriteVerbose(this,
                             "getting control with control type = " +
                             controlType);
                ctrlType =
                    UIAHelper.GetControlTypeByTypeName(controlType);
                WriteVerbose(cmdlet, "ctrlType = " + ctrlType.ProgrammaticName);
            }
            System.Windows.Automation.PropertyCondition ctrlTypeCondition = null,
            classCondition = null, titleCondition = null, autoIdCondition = null;
            // 20130127
            System.Windows.Automation.PropertyCondition valueCondition = null;

            //WriteVerbose(cmdlet, "ctrlType = " + ctrlType.ProgrammaticName);
            int conditionsCounter = 0;
            if (ctrlType != null) {

                ctrlTypeCondition =
                    new System.Windows.Automation.PropertyCondition(
                        System.Windows.Automation.AutomationElement.ControlTypeProperty,
                        ctrlType); //,
                // // 20130127
                // flags);
                WriteVerbose(cmdlet, "ControlTypeProperty '" +
                             ctrlType.ProgrammaticName + "' is used");
                // 20130128
                //conditionsCounter++;
            }
            // 20120828
            if (cmdlet.Class != null && cmdlet.Class != "")
                //if (null != cmdlet.Class && cmdlet.Class.Length > 0) {
            {

                classCondition =
                    new System.Windows.Automation.PropertyCondition(
                        System.Windows.Automation.AutomationElement.ClassNameProperty,
                        cmdlet.Class,
                        // 20130121
                        //PropertyConditionFlags.IgnoreCase);
                        // 20130127
                        flags);
                WriteVerbose(cmdlet, "ClassNameProperty '" +
                             cmdlet.Class + "' is used");
                conditionsCounter++;
            }
            if (cmdlet.AutomationId != null && cmdlet.AutomationId != "")
            {

                autoIdCondition =
                    new System.Windows.Automation.PropertyCondition(
                        System.Windows.Automation.AutomationElement.AutomationIdProperty,
                        cmdlet.AutomationId,
                        // 20130121
                        //PropertyConditionFlags.IgnoreCase);
                        // 20130127
                        flags);
                WriteVerbose(cmdlet, "AutomationIdProperty '" +
                             cmdlet.AutomationId + "' is used");
                conditionsCounter++;
            }
            if (cmdlet.Name != null && cmdlet.Name != "") // allow empty name
            {

                titleCondition =
                    new System.Windows.Automation.PropertyCondition(
                        System.Windows.Automation.AutomationElement.NameProperty,
                        cmdlet.Name,
                        // 20130121
                        //PropertyConditionFlags.IgnoreCase);
                        // 20130127
                        flags);
                WriteVerbose(cmdlet, "NameProperty '" +
                             cmdlet.Name + "' is used");
                conditionsCounter++;
            }
            // 20130127
            if (cmdlet.Value != null && cmdlet.Value != "")
            {

                valueCondition =
                    new System.Windows.Automation.PropertyCondition(
                        System.Windows.Automation.ValuePattern.ValueProperty,
                        cmdlet.Value,
                        // 20130121
                        //PropertyConditionFlags.IgnoreCase);
                        // 20130127
                        flags);
                WriteVerbose(cmdlet, "ValueProperty '" +
                             cmdlet.Value + "' is used");
                conditionsCounter++;
            }

            // 20130128
            //if (conditionsCounter > 1)
            // if there is more than one condition excepting ctrlTypeCondition
            if (1 < conditionsCounter)
            {

                try {
                    System.Collections.ArrayList l = new System.Collections.ArrayList();
                    if (classCondition != null)l.Add(classCondition);
                    // 20130128
                    //if (ctrlTypeCondition != null)l.Add(ctrlTypeCondition);
                    if (titleCondition != null)l.Add(titleCondition);
                    if (autoIdCondition != null)l.Add(autoIdCondition);
                    // 20130127
                    if (null != valueCondition)l.Add(valueCondition);
                    System.Type t = typeof(System.Windows.Automation.Condition);
                    System.Windows.Automation.Condition[] conds =
                        ((System.Windows.Automation.Condition[])l.ToArray(t));
                    // 20130128
                    if (AndVsOr) {

                        andConditions =
                            new System.Windows.Automation.AndCondition(conds);
                    } else {

                        orConditions =
                            new System.Windows.Automation.OrCondition(conds);
                    }
                    // 20130128
                    //                    if (null == ctrlTypeCondition) {
                    //                        //var ctrlTypeCond =
                    //                            //new Condi
                    //                    } else {
                    //                        //var ctrlTypeCond =
                    //                    }
                    if (null != andConditions) {

                        allConditions =
                            new System.Windows.Automation.AndCondition(
                                null == ctrlTypeCondition ? Condition.TrueCondition : ctrlTypeCondition,
                                andConditions);

                    }
                    if (null != orConditions) {

                        allConditions =
                            new System.Windows.Automation.AndCondition(
                                null == ctrlTypeCondition ? Condition.TrueCondition : ctrlTypeCondition,
                                orConditions);

                    }
                    //}
                    // 20130128
                    //conditions =
                    //    new System.Windows.Automation.AndCondition(conds);

                    WriteVerbose(cmdlet, "used conditions " +
                                 "ClassName = '" + classCondition.Value + "', " +
                                 "ControlType = '" + ctrlTypeCondition.Value + "', " +
                                 "Name = '" + titleCondition.Value + "', " +
                                 "AutomationId = '" + autoIdCondition.Value + "', " +  //"'");
                                 // 20130127
                                 "Value = '" + valueCondition.Value + "'");

                } catch (Exception eConditions) {
                    WriteDebug(cmdlet, "conditions related exception " +
                               eConditions.Message);
                }
                // 20130128
                //} else if (conditionsCounter == 1)
                //} else if ((1 == conditionsCounter) || (0 == conditionsCounter && null != ctrlTypeCondition))
                // 20130128
            } else if (1 == conditionsCounter && null != ctrlTypeCondition)
            {

                if (classCondition != null) { allConditions = new AndCondition(classCondition, ctrlTypeCondition); }
                else if (titleCondition != null) { allConditions = new AndCondition(titleCondition, ctrlTypeCondition); }
                else if (autoIdCondition != null) { allConditions = new AndCondition(autoIdCondition, ctrlTypeCondition); }
                else if (null != valueCondition) { allConditions = new AndCondition(valueCondition, ctrlTypeCondition); }
                WriteVerbose(cmdlet, "conditions: ctrlTypeCondition + a condition");

                // 20130128
            } else if ((0 == conditionsCounter && null != ctrlTypeCondition) ||
                       (1 == conditionsCounter && null == ctrlTypeCondition))
            {

                if (classCondition != null) { condition = classCondition; }
                else if (ctrlTypeCondition != null) { condition = ctrlTypeCondition; }
                else if (titleCondition != null) { condition = titleCondition; }
                else if (autoIdCondition != null) { condition = autoIdCondition; }
                // 20130127
                else if (null != valueCondition) { condition = valueCondition; }
                WriteVerbose(cmdlet, "condition " +
                             condition.GetType().Name + " '" +
                             condition.Value + "' is used");
            }
            // 20130128
            //else if (conditionsCounter == 0)
            else if (0 == conditionsCounter && null == ctrlTypeCondition)
            {

                WriteVerbose(cmdlet, "neither ControlType nor Class nor Name are present");

                return (new AndCondition(Condition.TrueCondition,
                                         Condition.TrueCondition));
            }
            try {

                Condition[] tempConditions = null;
                if (null != allConditions) {

                    tempConditions = allConditions.GetConditions();
                    conditionsToReturn = allConditions;

                }

                else if (null != andConditions) {

                    tempConditions = andConditions.GetConditions();

                    conditionsToReturn = andConditions;

                } else if (null != orConditions) {

                    tempConditions = orConditions.GetConditions();
                    conditionsToReturn = orConditions;

                } else if (condition != null) {

                    WriteVerbose(cmdlet, "conditions (only one): " +
                                 condition.Property.ProgrammaticName +
                                 " = " +
                                 condition.Value.ToString());
                    // 20130128
                    //andConditions =
                    allConditions =
                        new AndCondition(condition,
                                         Condition.TrueCondition);
                    // 20130128
                    conditionsToReturn = allConditions;

                }
                // 20130128
                if (null != tempConditions) {
                    for (int i = 0; i < tempConditions.Length; i++) {
                        WriteVerbose(cmdlet, "condition: " + tempConditions[i].ToString());
                    }
                }

                // 20130128
                //return andConditions;
                return conditionsToReturn;
            } catch {
                WriteVerbose(cmdlet, "conditions or condition are null");
                //return null;
                // 20130128
                //return andConditions;
                return conditionsToReturn;
            }
        }
Example #5
0
        // 20120828
        protected internal ArrayList getFiltredElementsCollection(GetCmdletBase cmdlet, ArrayList elementCollection)
        {
            ArrayList resultCollection = new ArrayList();

            return resultCollection;
        }