[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact]
        public void ThreeResults()
        {
            const string expectedName = "name";

            HasTimeoutCmdletBase cmdlet =
                new HasTimeoutCmdletBase();

            IFakeUiElement element01 =
                FakeFactory.GetAutomationElementExpected(
                    ControlType.Button,
                    expectedName,
                    string.Empty,
                    string.Empty,
                    string.Empty);

            IFakeUiElement element02 =
                FakeFactory.GetAutomationElementExpected(
                    ControlType.Button,
                    expectedName,
                    string.Empty,
                    string.Empty,
                    string.Empty);

            IFakeUiElement element03 =
                FakeFactory.GetAutomationElementExpected(
                    ControlType.Button,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty);

            IFakeUiElement element04 =
                FakeFactory.GetAutomationElementExpected(
                    ControlType.Button,
                    expectedName,
                    string.Empty,
                    string.Empty,
                    string.Empty);

            var controlSearcherData =
                new ControlSearcherData {
                Name         = expectedName,
                AutomationId = string.Empty,
                Class        = string.Empty,
                Value        = string.Empty
            };

            List <IUiElement> resultList =
                WindowSearcher.ReturnOnlyRightElements(
                    new[] { element01, element02, element03, element04 },
                    controlSearcherData,
                    false,
                    true);

            MbUnit.Framework.Assert.AreEqual(3, resultList.Count);
            // 20140312
            // MbUnit.Framework.Assert.Exists(resultList, e => e.Current.Name == expectedName); // ??
            MbUnit.Framework.Assert.Exists(resultList, e => e.GetCurrent().Name == expectedName); // ??
        }
 public GetControlCollectionCmdletBase(ControlSearcherData data)
 {
     InputObject   = data.InputObject;
     Name          = data.Name;
     AutomationId  = data.AutomationId;
     Class         = data.Class;
     Value         = data.Value;
     ControlType   = data.ControlType;
     CaseSensitive = data.CaseSensitive;
 }
 public GetControlCollectionCmdletBase(ControlSearcherData data)
 {
     InputObject = data.InputObject;
     Name = data.Name;
     AutomationId = data.AutomationId;
     Class = data.Class;
     Value = data.Value;
     ControlType = data.ControlType;
     CaseSensitive = data.CaseSensitive;
 }
예제 #4
0
        internal void FilterResultCollectionByWithControlParameter()
        {
            var  filteredWindows = new List <IUiElement>();
            bool exitInnerCycle;

            foreach (IUiElement window in ResultCollection)
            {
                if (!window.IsValid())
                {
                    continue;
                }

                var ControlSearcherData = new ControlSearcherData {
                    InputObject = new UiElement[] { (UiElement)window }
                };

                exitInnerCycle = false;
                bool addToResultCollection = false;
                foreach (Hashtable ht in (SearcherData as WindowSearcherData).WithControl)
                {
                    ControlSearcherData.SearchCriteria = new Hashtable[] { ht };

                    try {
                        var controlSearch = AutomationFactory.GetSearcherImpl <ControlSearcher>() as ControlSearcher;

                        List <IUiElement> controlsList = controlSearch.GetElements(ControlSearcherData, 0);

                        if (null == controlsList || 0 == controlsList.Count)
                        {
                            exitInnerCycle        = true;
                            addToResultCollection = false;
                            continue;
                        }
                        else
                        {
                            addToResultCollection = true;
                            break;
                        }
                    } catch (Exception) {
                        // forcing to a next loop
                        ResultCollection.Clear();
                        break;
                    }
                }

                ControlSearcherData = null;

                if (addToResultCollection)
                {
                    filteredWindows.Add(window);
                }
            }

            ResultCollection = filteredWindows;
        }
예제 #5
0
 public static List<IUiElement> GetResultList_ReturnOnlyRightElements(IEnumerable<IUiElement> elements, ControlSearcherData data, bool useWildcardOrRegex)
 {
     List<IUiElement> resultList =
         WindowSearcher.ReturnOnlyRightElements(
             elements,
             data,
             false,
             useWildcardOrRegex);
     
     return resultList;
 }
예제 #6
0
 public static List<IUiElement> GetResultList_ViaWildcards(IUiElement element, Condition condition, ControlSearcherData data)
 {
     List<IUiElement> resultList =
         ControlSearcher.SearchByWildcardOrRegexViaUia(
             element,
             data,
             condition,
             true);
     
     return resultList;
 }
예제 #7
0
 internal static classic.Condition GetWildcardSearchCondition(ControlSearcherData data)
 {
     classic.Condition controlTypeCondition = classic.Condition.TrueCondition;
     if (null == data.ControlType || 0 == data.ControlType.Length)
     {
         return(controlTypeCondition);
     }
     controlTypeCondition =
         GetControlTypeCondition(
             data.ControlType);
     return(controlTypeCondition);
 }
예제 #8
0
 public static List<IUiElement> GetResultList_ViaWildcards_Legacy(IUiElement element, Condition condition, ControlSearcherData data)
 {
     var cmdletDerived = new GetControlCollectionCmdletBase();
     
     List<IUiElement> resultList =
         cmdletDerived.GetAutomationElementsWithFindAll(
             element,
             data,
             condition,
             false,
             false,
             false,
             true);
     
     return resultList;
 }
예제 #9
0
        public classic.Condition[] GetControlsConditions(ControlSearcherData data)
        {
            var conditions = new List <classic.Condition>();

            if (null != data.ControlType && 0 < data.ControlType.Length)
            {
                foreach (string controlTypeName in data.ControlType)
                {
                    conditions.Add(GetWildcardSearchCondition(data));
                }
            }
            else
            {
                conditions.Add(GetWildcardSearchCondition(data));
            }
            return(conditions.ToArray());
        }
예제 #10
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);
        }
예제 #11
0
        internal static IUiEltCollection PerformFindAll(this IExtendedModelHolder holder, classic.ControlType controlType)
        {
            try {
                var controlSearcherData =
                    new ControlSearcherData {
                    ControlType = controlType.ConvertControlTypeToStringArray(),
                    InputObject = new IUiElement[] { holder.GetParentElement() }
                };

                var controlSearcher =
                    AutomationFactory.GetSearcherImpl <ControlSearcher>();

                return(AutomationFactory.GetUiEltCollection(
                           controlSearcher.GetElements(
                               controlSearcherData,
                               holder.Seconds)));
            } catch (Exception) {
                return(new UiEltCollection(true));
            }
        }
예제 #12
0
        private void TestParametersAgainstCollection(
            Hashtable[] inputData,
            IEnumerable <IUiElement> collection,
            bool expectedResult)
        {
            // Arrange
            var data =
                new ControlSearcherData {
                SearchCriteria = inputData
            };

            Condition condition =
                ControlSearcher.GetWildcardSearchCondition(data);

            IUiElement element =
                FakeFactory.GetElement_ForFindAll(
                    collection,
                    condition);

            var cmdlet =
                new WaitUiaControlStateCommand {
                SearchCriteria = inputData,
                InputObject    = new[] { element },
                Timeout        = 10
            };

            // Act
            var command = new WaitControlStateCommand(cmdlet);

            command.Execute();

            // Assert
            MbUnit.Framework.Assert.AreEqual <bool>(
                expectedResult,
                (bool)PSTestLib.UnitTestOutput.LastOutput[0]);
            Assert.Equal <bool>(
                expectedResult,
                (bool)PSTestLib.UnitTestOutput.LastOutput[0]);
        }
 private void TestParametersAgainstCollection(
     Hashtable[] inputData,
     IEnumerable<IUiElement> collection,
     bool expectedResult)
 {
     // Arrange
     var data =
         new ControlSearcherData {
         SearchCriteria = inputData
     };
     
     Condition condition =
         ControlSearcher.GetWildcardSearchCondition(data);
     
     IUiElement element =
         FakeFactory.GetElement_ForFindAll(
             collection,
             condition);
     
     var cmdlet =
         new WaitUiaControlStateCommand {
         SearchCriteria = inputData,
         InputObject = new[] { element },
         Timeout = 10
     };
     
     // Act
     var command = new WaitControlStateCommand(cmdlet);
     command.Execute();
     
     // Assert
     MbUnit.Framework.Assert.AreEqual<bool>(
         expectedResult,
         (bool)PSTestLib.UnitTestOutput.LastOutput[0]);
     Xunit.Assert.Equal<bool>(
         expectedResult,
         (bool)PSTestLib.UnitTestOutput.LastOutput[0]);
 }
        [NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact]
        public void NoResults_ZeroInput()
        {
            HasTimeoutCmdletBase cmdlet =
                new HasTimeoutCmdletBase();

            var controlSearcherData =
                new ControlSearcherData {
                Name         = string.Empty,
                AutomationId = string.Empty,
                Class        = string.Empty,
                Value        = string.Empty,
                ControlType  = new string[] {}
            };

            List <IUiElement> resultList =
                WindowSearcher.ReturnOnlyRightElements(
                    new UiElement[] {},
                    controlSearcherData,
                    false,
                    true);

            MbUnit.Framework.Assert.AreEqual(0, resultList.Count);
        }
        // 20130127
//        [UiaParameterNotUsed][Parameter(Mandatory = false)]
//        public SwitchParameter CaseSensitive { get; set; }
        #endregion Parameters

        // not used
//        protected void GetAutomationElementsViaWildcards_FindAll(
//            IUiElement inputObject,
//            classic.AndCondition conditions,
//            bool caseSensitive,
//            bool onlyOneResult,
//            bool onlyTopLevel,
//            bool viaWildcardOrRegex)
//        {
//            if (!CheckAndPrepareInput(this)) { return; }
//
//            var controlSearcherData =
//                new ControlSearcherData {
//                Name = this.Name,
//                AutomationId = this.AutomationId,
//                Class = this.Class,
//                Value = this.Value,
//                ControlType = this.ControlType
//            };
//
//            GetAutomationElementsWithFindAll(
//                inputObject,
//                controlSearcherData,
//                conditions,
//                caseSensitive,
//                onlyOneResult,
//                onlyTopLevel,
//                viaWildcardOrRegex);
//        }

        internal List <IUiElement> GetAutomationElementsViaWildcards_FindAll(
            ControlSearcherData data,
            IUiElement inputObject,
            classic.Condition conditions,
            bool caseSensitive,
            bool onlyOneResult,
            bool onlyTopLevel,
            bool viaWildcardOrRegex)
        {
            var resultCollection = new List <IUiElement>(); // ? make it null ??

            resultCollection =
                GetAutomationElementsWithFindAll(
                    inputObject,
                    data,
                    conditions,
                    caseSensitive,
                    onlyOneResult,
                    onlyTopLevel,
                    viaWildcardOrRegex);

            return(resultCollection);
        }
        internal List <IUiElement> GetAutomationElementsWithFindAll(
            IUiElement element,
            ControlSearcherData data,
            classic.Condition conditions,
            bool caseSensitiveParam,
            bool onlyOneResult,
            bool onlyTopLevel,
            bool viaWildcardOrRegex)
        {
            var resultCollection = new List <IUiElement>();

            try {
                IUiEltCollection results =
                    element.FindAll(
                        classic.TreeScope.Descendants,
                        conditions);

                resultCollection =
                    WindowSearcher.ReturnOnlyRightElements(
                        results,
                        data,
                        caseSensitiveParam,
                        viaWildcardOrRegex);

                if (null != results)
                {
                    // results.Dispose(); // taboo!
                    results = null;
                }
                // results = null;
            }
            catch { //(Exception eWildCardSearch) {
            }

            return(resultCollection);
        }
예제 #17
0
        public static List <IUiElement> GetResultList_ReturnOnlyRightElements(IEnumerable <IUiElement> elements, ControlSearcherData data, bool useWildcardOrRegex)
        {
            List <IUiElement> resultList =
                WindowSearcher.ReturnOnlyRightElements(
                    elements,
                    data,
                    false,
                    useWildcardOrRegex);

            return(resultList);
        }
예제 #18
0
        public static List <IUiElement> GetResultList_ViaWildcards(IUiElement element, Condition condition, ControlSearcherData data)
        {
            List <IUiElement> resultList =
                ControlSearcher.SearchByWildcardOrRegexViaUia(
                    element,
                    data,
                    condition,
                    true);

            return(resultList);
        }
 internal List<IUiElement> GetAutomationElementsWithFindAll(
     IUiElement element,
     ControlSearcherData data,
     classic.Condition conditions,
     bool caseSensitiveParam,
     bool onlyOneResult,
     bool onlyTopLevel,
     bool viaWildcardOrRegex)
 {
     var resultCollection = new List<IUiElement>();
     
     try {
         
         IUiEltCollection results =
             element.FindAll(
                 classic.TreeScope.Descendants,
                 conditions);
         
         resultCollection =
             WindowSearcher.ReturnOnlyRightElements(
                 results,
                 data,
                 caseSensitiveParam,
                 viaWildcardOrRegex);
         
         if (null != results) {
             // results.Dispose(); // taboo!
             results = null;
         }
         // results = null;
         
     }
     catch { //(Exception eWildCardSearch) {
         
     }
     
     return resultCollection;
 }
예제 #20
0
        internal IEnumerable <IUiElement> SearchByWildcardViaWin32(
            IUiElement inputObject,
            ControlSearcherData data,
            HandleCollector handleCollector)
        {
            var tempListWin32 = new List <IUiElement>();

            if (!string.IsNullOrEmpty(data.Name) || !string.IsNullOrEmpty(data.Value))
            {
                var controlFrom32Provider = AutomationFactory.GetObject <ControlFromWin32Provider>();

                var singleControlSearcherData = new SingleControlSearcherData {
                    InputObject  = inputObject,
                    Name         = data.Name,
                    Value        = data.Value,
                    AutomationId = data.AutomationId,
                    Class        = data.Class
                };

                controlFrom32Provider.HandleCollector = handleCollector;

                tempListWin32.AddRange(
                    controlFrom32Provider.GetElements(
                        singleControlSearcherData.ConvertSingleControlSearcherDataToControlSearcherTemplateData()));
            }

            var resultList = new List <IUiElement>();

            foreach (IUiElement tempElement3 in tempListWin32)
            {
                bool goFurther = true;

                if (null != data.ControlType && 0 < data.ControlType.Length)
                {
                    // 20140312
                    // goFurther &= !data.ControlType.Any(controlTypeName => String.Equals(tempElement3.Current.ControlType.ProgrammaticName.Substring(12), controlTypeName, StringComparison.CurrentCultureIgnoreCase));
                    goFurther &= !data.ControlType.Any(controlTypeName => String.Equals(tempElement3.GetCurrent().ControlType.ProgrammaticName.Substring(12), controlTypeName, StringComparison.CurrentCultureIgnoreCase));
                }
                else
                {
                    goFurther = false;
                }

                if (goFurther)
                {
                    continue;
                }

                if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length)
                {
                    resultList.Add(tempElement3);
                }
                else
                {
                    if (!TestControlWithAllSearchCriteria(data.SearchCriteria, tempElement3))
                    {
                        continue;
                    }
                    resultList.Add(tempElement3);
                }
            }

            if (null != tempListWin32)
            {
                tempListWin32.Clear();
                tempListWin32 = null;
            }

            return(resultList);
        }
예제 #21
0
        internal static List <IUiElement> SearchByWildcardOrRegexViaUia(
            IUiElement inputObject,
            ControlSearcherData data,
            classic.Condition conditionsForWildCards,
            bool viaWildcardOrRegex)
        {
            var resultCollection =
                new List <IUiElement>();

            if (null == inputObject)
            {
                return(resultCollection);
            }

            try {
                var controlSearcherData =
                    new ControlSearcherData {
                    InputObject   = data.InputObject ?? (new UiElement[] { (UiElement)UiElement.RootElement }),
                    Name          = data.Name,
                    AutomationId  = data.AutomationId,
                    Class         = data.Class,
                    Value         = data.Value,
                    ControlType   = null != data.ControlType && 0 < data.ControlType.Length ? data.ControlType : (new string[] {}),
                    CaseSensitive = caseSensitive
                };

                var cmdlet1 = new GetControlCollectionCmdletBase(controlSearcherData);

                try {
                    List <IUiElement> tempList =
                        cmdlet1.GetAutomationElementsViaWildcards_FindAll(
                            controlSearcherData,
                            inputObject,
                            conditionsForWildCards,
                            cmdlet1.CaseSensitive,
                            false,
                            false,
                            viaWildcardOrRegex);

                    if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length)
                    {
                        resultCollection.AddRange(tempList);
                    }
                    else
                    {
                        foreach (IUiElement tempElement2 in tempList.Where(elt => TestControlWithAllSearchCriteria(data.SearchCriteria, elt)))
                        {
                            resultCollection.Add(tempElement2);
                        }
                    }

                    if (null != tempList)
                    {
                        tempList.Clear();
                        tempList = null;
                    }

                    return(resultCollection);
                } catch (Exception eUnexpected) {
                    (new GetControlCmdletBase()).WriteError(
                        new GetControlCmdletBase(),
                        "The input control or window has been possibly lost." +
                        eUnexpected.Message,
                        "UnexpectedError",
                        ErrorCategory.ObjectNotFound,
                        true);
                }

                cmdlet1 = null;

                return(resultCollection);
            } catch (Exception eWildCardSearch) {
                (new GetControlCmdletBase()).WriteError(
                    new GetControlCmdletBase(),
                    "The input control or window has been possibly lost." +
                    eWildCardSearch.Message,
                    "UnexpectedError",
                    ErrorCategory.ObjectNotFound,
                    true);

                return(resultCollection);
            }
        }
예제 #22
0
 internal static classic.Condition GetWildcardSearchCondition(ControlSearcherData data)
 {
     classic.Condition controlTypeCondition = classic.Condition.TrueCondition;
     if (null == data.ControlType || 0 == data.ControlType.Length) return controlTypeCondition;
     controlTypeCondition =
         GetControlTypeCondition(
             data.ControlType);
     return controlTypeCondition;
 }
예제 #23
0
 public classic.Condition[] GetControlsConditions(ControlSearcherData data)
 {
     var conditions = new List<classic.Condition>();
     
     if (null != data.ControlType && 0 < data.ControlType.Length) {
         foreach (string controlTypeName in data.ControlType)
         {
             conditions.Add(GetWildcardSearchCondition(data));
         }
     } else{
         conditions.Add(GetWildcardSearchCondition(data));
     }
     return conditions.ToArray();
 }
예제 #24
0
 internal List<IUiElement> GetWindowCollectionByPid(
     IUiElement rootElement,
     WindowSearcherData data)
 {
     classic.AndCondition conditionsForRecurseSearch = null;
     
     var elementsByProcessId =
         new List<IUiElement>();
     
     // 20141001
     // if ((null != data.Name && 0 < data.Name.Count()) ||
     if ((null != data.Name && data.Name.Any()) ||
         !string.IsNullOrEmpty(data.AutomationId) ||
         !string.IsNullOrEmpty(data.Class)) {
         
         data.Recurse = true;
     }
     
     var conditionWindowPaneMenu =
         new classic.OrCondition(
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Window),
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Pane),
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Menu));
     
     foreach (int processId in data.ProcessIds) {
         
         conditionsForRecurseSearch =
             new classic.AndCondition(
                 new classic.PropertyCondition(
                     classic.AutomationElement.ProcessIdProperty,
                     processId),
                 new classic.PropertyCondition(
                     classic.AutomationElement.ControlTypeProperty,
                     classic.ControlType.Window));
             
         var conditionsProcessId =
             new classic.AndCondition(
                 new classic.PropertyCondition(
                     classic.AutomationElement.ProcessIdProperty,
                     processId),
                 conditionWindowPaneMenu);
         
         try {
             
             if (data.Recurse) {
                 if (data.First) {
                     
                     IUiElement rootWindowElement =
                         rootElement.FindFirst(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != rootWindowElement) {
                         elementsByProcessId.Add(rootWindowElement);
                     }
                     
                 } else {
                     
                     IUiEltCollection rootCollection =
                         rootElement.FindAll(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != rootCollection && 0 < rootCollection.Count)
                     {
                         elementsByProcessId.AddRange(rootCollection.Cast<IUiElement>());
                     }
                 }
                 
             } else {
                 
                 if (data.First) {
                     
                     IUiElement tempElement =
                         rootElement.FindFirst(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != tempElement) {
                         
                         elementsByProcessId.Add(tempElement);
                     }
                 } else {
                     
                     IUiEltCollection tempCollection =
                         rootElement.FindAll(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != tempCollection && 0 < tempCollection.Count) {
                         
                         elementsByProcessId.AddRange(tempCollection.Cast<IUiElement>());
                     }
                 }
             }
         } catch (Exception) {
             
             // WriteVerbose(
             //     this,
             //     "exception: " +
             //     eGetFirstChildOfRootByProcessId.Message);
         }
     }
     
     if (!data.Recurse ||
         // 20141001
         // ((null == data.Name || 0 == data.Name.Count()) && string.IsNullOrEmpty(data.AutomationId) &&
         ((null == data.Name || !data.Name.Any()) && string.IsNullOrEmpty(data.AutomationId) &&
          string.IsNullOrEmpty(data.Class))) return elementsByProcessId;
     
     var resultList =
         new List<IUiElement>();
     /*
     List<IUiElement> resultList =
         new List<IUiElement>();
     */
     
     // 20141001
     // if (null != data.Name && 0 < data.Name.Count()) {
     if (null != data.Name && data.Name.Any()) {
         foreach (string name in data.Name) {
             
             var controlSearcherData =
                 new ControlSearcherData {
                 Name = name,
                 AutomationId = data.AutomationId,
                 Class = data.Class,
                 Value = string.Empty,
                 ControlType = new string[]{ "Window" } 
             };
             
             resultList.AddRange(
                 ReturnOnlyRightElements(
                     elementsByProcessId,
                     controlSearcherData,
                     false,
                     true));
             
         }
     } else {
         
         var controlSearcherData =
             new ControlSearcherData {
             Name = string.Empty,
             AutomationId = data.AutomationId,
             Class = data.Class,
             Value = string.Empty,
             ControlType = new string[]{ "Window" } 
         };
         
         resultList.AddRange(
             ReturnOnlyRightElements(
                 elementsByProcessId,
                 controlSearcherData,
                 false,
                 true));
     }
     
     elementsByProcessId = resultList;
     
     // 20140121
     // never !
     //            if (null != resultList) {
     //                resultList.Clear();
     //                resultList = null;
     //            }
     
     return elementsByProcessId;
 }
예제 #25
0
        List<IUiElement> GetWindowCollectionByName(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            var windowCollectionByProperties =
                new List<IUiElement>();
            var resultCollection =
                new List<IUiElement>();
            
            if (null == data.Name) {
                // 20141001
                // data.Name = new string[]{ string.Empty };
                data.Name = new []{ string.Empty };
            }
            
            classic.OrCondition conditionsSet = null;
            if (data.Recurse) {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        classic.Condition.FalseCondition);
            } else {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Pane),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Menu));
            }
            
            foreach (string windowTitle in data.Name) {
                
                IUiEltCollection windowCollection =
                    rootElement.FindAll(data.Recurse ? classic.TreeScope.Descendants : classic.TreeScope.Children, conditionsSet);
                
                var controlSearcherData =
                    new ControlSearcherData {
                    Name = windowTitle,
                    AutomationId = data.AutomationId,
                    Class = data.Class,
                    Value = string.Empty,
                    // 20141001
                    // ControlType = (new string[]{ "Window", "Pane", "Menu" })
                    ControlType = (new []{ "Window", "Pane", "Menu" })
                };
                
                windowCollectionByProperties =
                    ReturnOnlyRightElements(
                        windowCollection,
                        controlSearcherData,
                        false,
                        true);
                    
                try {
                    
                    if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
                        
                        foreach (IUiElement aeWndByTitle in windowCollectionByProperties
                            .Where(aeWndByTitle => aeWndByTitle != null && (int)aeWndByTitle.GetCurrent().ProcessId > 0))
                        {
                            resultCollection.Add(aeWndByTitle);
                        }
                        
                        windowCollectionByProperties.Clear();
                        
                    } else {
                        
                        IUiElement tempElement = null;
                        
                        // one more attempt using the FindWindow function
                        IntPtr wndHandle = NativeMethods.FindWindowByCaption(IntPtr.Zero, windowTitle);
                        // 20141001
                        // if (wndHandle != null && wndHandle != IntPtr.Zero) {
                        if (wndHandle != IntPtr.Zero) {
                            tempElement =
                                UiElement.FromHandle(wndHandle);
                        }
                        
                        if (null == tempElement || (int) tempElement.GetCurrent().ProcessId <= 0) continue;
                        
                        resultCollection.Add(tempElement);
                    }
                }
                catch {}
                
                // 20140122
                // AutomationFactory.DisposeChildKernel();
                
                // 20140131
//                if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
//                    foreach (IUiElement element in windowCollectionByProperties) {
//                        element.Dispose();
//                    }
//                }
//                if (null != windowCollection && 0 < windowCollection.Count) {
//                    foreach (IUiElement element in windowCollection) {
//                        element.Dispose();
//                    }
//                }
            }
            
            return resultCollection;
        }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable<IUiElement> collection,
            int expectedNumberOfElements)
        {
            // Arrange
            string controlTypeString = string.Empty;
            if (null != controlType) {
                controlTypeString = controlType.ProgrammaticName.Substring(12);
            }
            
            ControlType[] controlTypes =
                new[] { controlType };
            
            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue);
            
            Condition condition =
                ControlSearcher.GetWildcardSearchCondition(
                    new ControlSearcherData {
                        ControlType = controlTypes.ConvertControlTypeToStringArray(),
                        Name = name,
                        AutomationId = automationId,
                        Class = className,
                        Value = txtValue
                    });
            
            IUiElement element =
                FakeFactory.GetElement_ForFindAll(
                    collection,
                    condition);
            
            var controlSearcherData =
                new ControlSearcherData {
                // InputObject = new IUiElement[] { CurrentData.CurrentWindow };
                Name = name,
                AutomationId = automationId,
                Class = className,
                Value = txtValue
            };
            
            // Act
            var resultList = RealCodeCaller.GetResultList_ViaWildcards_Legacy(element, condition, controlSearcherData);
            
            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Xunit.Assert.Equal(expectedNumberOfElements, resultList.Count);
            // 20140312
//            if (!string.IsNullOrEmpty(name)) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.Name == name);
//                resultList.All(x => x.Current.Name == name);
//            }
//            if (!string.IsNullOrEmpty(automationId)) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.AutomationId == automationId);
//                resultList.All(x => x.Current.AutomationId == automationId);
//            }
//            if (!string.IsNullOrEmpty(className)) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ClassName == className);
//                resultList.All(x => x.Current.ClassName == className);
//            }
//            if (null != controlType) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ControlType == controlType);
//                resultList.All(x => x.Current.ControlType == controlType);
//            }
            if (!string.IsNullOrEmpty(name)) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().Name == name);
                resultList.All(x => x.GetCurrent().Name == name);
            }
            if (!string.IsNullOrEmpty(automationId)) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().AutomationId == automationId);
                resultList.All(x => x.GetCurrent().AutomationId == automationId);
            }
            if (!string.IsNullOrEmpty(className)) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().ClassName == className);
                resultList.All(x => x.GetCurrent().ClassName == className);
            }
            if (null != controlType) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().ControlType == controlType);
                resultList.All(x => x.GetCurrent().ControlType == controlType);
            }
            if (string.IsNullOrEmpty(txtValue)) return;
            MbUnit.Framework.Assert.ForAll(
                resultList
                    .Cast<IUiElement>()
                    .ToList<IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return valuePattern != null && valuePattern.Current.Value == txtValue;
                    });
            Xunit.Assert.True(    
                resultList.All(
                    x => {
                             IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                             return valuePattern != null && valuePattern.Current.Value == txtValue;
                    })
                             );
        }
        // 20130127
//        [UiaParameterNotUsed][Parameter(Mandatory = false)]
//        public SwitchParameter CaseSensitive { get; set; }
        #endregion Parameters
        
        // not used
//        protected void GetAutomationElementsViaWildcards_FindAll(
//            IUiElement inputObject,
//            classic.AndCondition conditions,
//            bool caseSensitive,
//            bool onlyOneResult,
//            bool onlyTopLevel,
//            bool viaWildcardOrRegex)
//        {
//            if (!CheckAndPrepareInput(this)) { return; }
//            
//            var controlSearcherData =
//                new ControlSearcherData {
//                Name = this.Name,
//                AutomationId = this.AutomationId,
//                Class = this.Class,
//                Value = this.Value,
//                ControlType = this.ControlType
//            };
//            
//            GetAutomationElementsWithFindAll(
//                inputObject,
//                controlSearcherData,
//                conditions,
//                caseSensitive,
//                onlyOneResult,
//                onlyTopLevel,
//                viaWildcardOrRegex);
//        }
        
        internal List<IUiElement> GetAutomationElementsViaWildcards_FindAll(
            ControlSearcherData data,
            IUiElement inputObject,
            classic.Condition conditions,
            bool caseSensitive,
            bool onlyOneResult,
            bool onlyTopLevel,
            bool viaWildcardOrRegex)
        {
            var resultCollection = new List<IUiElement>(); // ? make it null ??
            
            resultCollection =
                GetAutomationElementsWithFindAll(
                    inputObject,
                    data,
                    conditions,
                    caseSensitive,
                    onlyOneResult,
                    onlyTopLevel,
                    viaWildcardOrRegex);
            
            return resultCollection;
        }
예제 #28
0
        internal static List<IUiElement> SearchByWildcardOrRegexViaUia(
            IUiElement inputObject,
            ControlSearcherData data,
            classic.Condition conditionsForWildCards,
            bool viaWildcardOrRegex)
        {
            var resultCollection =
                new List<IUiElement>();
            
            if (null == inputObject) return resultCollection;
            
            try {
                var controlSearcherData =
                    new ControlSearcherData {
                    InputObject = data.InputObject ?? (new UiElement[]{ (UiElement)UiElement.RootElement }),
                    Name = data.Name,
                    AutomationId = data.AutomationId,
                    Class = data.Class,
                    Value = data.Value,
                    ControlType = null != data.ControlType && 0 < data.ControlType.Length ? data.ControlType : (new string[] {}),
                    CaseSensitive = caseSensitive
                };
                
                var cmdlet1 = new GetControlCollectionCmdletBase(controlSearcherData);
                
                try {
                    
                    List<IUiElement> tempList =
                        cmdlet1.GetAutomationElementsViaWildcards_FindAll(
                            controlSearcherData,
                            inputObject,
                            conditionsForWildCards,
                            cmdlet1.CaseSensitive,
                            false,
                            false,
                            viaWildcardOrRegex);
                    
                    if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length) {
                        
                        resultCollection.AddRange(tempList);
                    } else {
                        
                        foreach (IUiElement tempElement2 in tempList.Where(elt => TestControlWithAllSearchCriteria(data.SearchCriteria, elt))) {
                            resultCollection.Add(tempElement2);
                        }
                    }
                    
                    if (null != tempList) {
                        tempList.Clear();
                        tempList = null;
                    }
                    
                    return resultCollection;
                    
                } catch (Exception eUnexpected) {

                    (new GetControlCmdletBase()).WriteError(
                        new GetControlCmdletBase(),
                        "The input control or window has been possibly lost." +
                        eUnexpected.Message,
                        "UnexpectedError",
                        ErrorCategory.ObjectNotFound,
                        true);
                }
                
                cmdlet1 = null;
                
                return resultCollection;
                
            } catch (Exception eWildCardSearch) {

                (new GetControlCmdletBase()).WriteError(
                    new GetControlCmdletBase(),
                    "The input control or window has been possibly lost." +
                    eWildCardSearch.Message,
                    "UnexpectedError",
                    ErrorCategory.ObjectNotFound,
                    true);
                
                return resultCollection;
            }
        }
예제 #29
0
        List <IUiElement> GetWindowCollectionByName(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            var windowCollectionByProperties =
                new List <IUiElement>();
            var resultCollection =
                new List <IUiElement>();

            if (null == data.Name)
            {
                // 20141001
                // data.Name = new string[]{ string.Empty };
                data.Name = new [] { string.Empty };
            }

            classic.OrCondition conditionsSet = null;
            if (data.Recurse)
            {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        classic.Condition.FalseCondition);
            }
            else
            {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Pane),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Menu));
            }

            foreach (string windowTitle in data.Name)
            {
                IUiEltCollection windowCollection =
                    rootElement.FindAll(data.Recurse ? classic.TreeScope.Descendants : classic.TreeScope.Children, conditionsSet);

                var controlSearcherData =
                    new ControlSearcherData {
                    Name         = windowTitle,
                    AutomationId = data.AutomationId,
                    Class        = data.Class,
                    Value        = string.Empty,
                    // 20141001
                    // ControlType = (new string[]{ "Window", "Pane", "Menu" })
                    ControlType = (new [] { "Window", "Pane", "Menu" })
                };

                windowCollectionByProperties =
                    ReturnOnlyRightElements(
                        windowCollection,
                        controlSearcherData,
                        false,
                        true);

                try {
                    if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count)
                    {
                        foreach (IUiElement aeWndByTitle in windowCollectionByProperties
                                 .Where(aeWndByTitle => aeWndByTitle != null && (int)aeWndByTitle.GetCurrent().ProcessId > 0))
                        {
                            resultCollection.Add(aeWndByTitle);
                        }

                        windowCollectionByProperties.Clear();
                    }
                    else
                    {
                        IUiElement tempElement = null;

                        // one more attempt using the FindWindow function
                        IntPtr wndHandle = NativeMethods.FindWindowByCaption(IntPtr.Zero, windowTitle);
                        // 20141001
                        // if (wndHandle != null && wndHandle != IntPtr.Zero) {
                        if (wndHandle != IntPtr.Zero)
                        {
                            tempElement =
                                UiElement.FromHandle(wndHandle);
                        }

                        if (null == tempElement || (int)tempElement.GetCurrent().ProcessId <= 0)
                        {
                            continue;
                        }

                        resultCollection.Add(tempElement);
                    }
                }
                catch {}

                // 20140122
                // AutomationFactory.DisposeChildKernel();

                // 20140131
//                if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
//                    foreach (IUiElement element in windowCollectionByProperties) {
//                        element.Dispose();
//                    }
//                }
//                if (null != windowCollection && 0 < windowCollection.Count) {
//                    foreach (IUiElement element in windowCollection) {
//                        element.Dispose();
//                    }
//                }
            }

            return(resultCollection);
        }
예제 #30
0
 internal IEnumerable<IUiElement> SearchByWildcardViaWin32(
     IUiElement inputObject,
     ControlSearcherData data,
     HandleCollector handleCollector)
 {
     var tempListWin32 = new List<IUiElement>();
     
     if (!string.IsNullOrEmpty(data.Name) || !string.IsNullOrEmpty(data.Value)) {
         
         var controlFrom32Provider = AutomationFactory.GetObject<ControlFromWin32Provider>();
         
         var singleControlSearcherData = new SingleControlSearcherData {
             InputObject = inputObject,
             Name = data.Name,
             Value = data.Value,
             AutomationId = data.AutomationId,
             Class = data.Class
         };
         
         controlFrom32Provider.HandleCollector = handleCollector;
         
         tempListWin32.AddRange(
             controlFrom32Provider.GetElements(
                 singleControlSearcherData.ConvertSingleControlSearcherDataToControlSearcherTemplateData()));
     }
     
     var resultList = new List<IUiElement>();
     
     foreach (IUiElement tempElement3 in tempListWin32) {
         
         bool goFurther = true;
         
         if (null != data.ControlType && 0 < data.ControlType.Length) {
             
             // 20140312
             // goFurther &= !data.ControlType.Any(controlTypeName => String.Equals(tempElement3.Current.ControlType.ProgrammaticName.Substring(12), controlTypeName, StringComparison.CurrentCultureIgnoreCase));
             goFurther &= !data.ControlType.Any(controlTypeName => String.Equals(tempElement3.GetCurrent().ControlType.ProgrammaticName.Substring(12), controlTypeName, StringComparison.CurrentCultureIgnoreCase));
             
         } else {
             goFurther = false;
         }
         
         if (goFurther) continue;
         
         if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length) {
             
             resultList.Add(tempElement3);
         } else {
             
             if (!TestControlWithAllSearchCriteria(data.SearchCriteria, tempElement3)) continue;
             resultList.Add(tempElement3);
         }
     }
     
     if (null != tempListWin32) {
         tempListWin32.Clear();
         tempListWin32 = null;
     }
     
     return resultList;
 }
예제 #31
0
        internal static classic.Condition GetExactSearchCondition(ControlSearcherData data)
        {
            classic.PropertyConditionFlags flags =
                data.CaseSensitive ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase;

            classic.Condition controlTypeCondition = classic.Condition.TrueCondition;
            if (null != data.ControlType && 0 < data.ControlType.Length)
            {
                controlTypeCondition =
                    GetControlTypeCondition(
                        data.ControlType);
            }

            var propertyCollection =
                new List <classic.PropertyCondition>();

            if (!string.IsNullOrEmpty(data.Name))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.AutomationElement.NameProperty,
                        data.Name));
            }
            if (!string.IsNullOrEmpty(data.AutomationId))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.AutomationElement.AutomationIdProperty,
                        data.AutomationId));
            }
            if (!string.IsNullOrEmpty(data.Class))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.AutomationElement.ClassNameProperty,
                        data.Class));
            }
            if (!string.IsNullOrEmpty(data.Value))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.ValuePattern.ValueProperty,
                        data.Value));
            }

            classic.Condition propertyCondition =
                0 == propertyCollection.Count ? null : (
                    1 == propertyCollection.Count ? propertyCollection[0] : (classic.Condition)GetAndCondition(propertyCollection)
                    );

            if (null == propertyCondition)
            {
                return(controlTypeCondition);
            }
            else
            {
                return(null == controlTypeCondition ? propertyCondition : new classic.AndCondition(
                           new classic.Condition[] {
                    propertyCondition,
                    controlTypeCondition
                }));
            }
        }
예제 #32
0
 internal static classic.Condition GetExactSearchCondition(ControlSearcherData data)
 {
     classic.PropertyConditionFlags flags =
         data.CaseSensitive ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase;
     
     classic.Condition controlTypeCondition = classic.Condition.TrueCondition;
     if (null != data.ControlType && 0 < data.ControlType.Length) {
         controlTypeCondition =
             GetControlTypeCondition(
                 data.ControlType);
     }
     
     var propertyCollection =
         new List<classic.PropertyCondition>();
     
     if (!string.IsNullOrEmpty(data.Name)) {
         propertyCollection.Add(
             new classic.PropertyCondition(
                 classic.AutomationElement.NameProperty,
                 data.Name));
     }
     if (!string.IsNullOrEmpty(data.AutomationId)) {
         propertyCollection.Add(
             new classic.PropertyCondition(
                 classic.AutomationElement.AutomationIdProperty,
                 data.AutomationId));
     }
     if (!string.IsNullOrEmpty(data.Class)) {
         propertyCollection.Add(
             new classic.PropertyCondition(
                 classic.AutomationElement.ClassNameProperty,
                 data.Class));
     }
     if (!string.IsNullOrEmpty(data.Value)) {
         propertyCollection.Add(
             new classic.PropertyCondition(
                 classic.ValuePattern.ValueProperty,
                 data.Value));
     }
     
     classic.Condition propertyCondition =
         0 == propertyCollection.Count ? null : (
             1 == propertyCollection.Count ? propertyCollection[0] : (classic.Condition)GetAndCondition(propertyCollection)
            );
     
     if (null == propertyCondition) {
         return controlTypeCondition;
     } else {
         return null == controlTypeCondition ? propertyCondition : new classic.AndCondition(
             new classic.Condition[] {
                 propertyCondition,
                 controlTypeCondition
             });
     }
 }
 public void ThreeResults()
 {
     const string expectedName = "name";
     
     HasTimeoutCmdletBase cmdlet =
         new HasTimeoutCmdletBase();
     
     IFakeUiElement element01 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             expectedName,
             string.Empty,
             string.Empty,
             string.Empty);
     
     IFakeUiElement element02 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             expectedName,
             string.Empty,
             string.Empty,
             string.Empty);
     
     IFakeUiElement element03 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             string.Empty,
             string.Empty,
             string.Empty,
             string.Empty);
     
     IFakeUiElement element04 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             expectedName,
             string.Empty,
             string.Empty,
             string.Empty);
     
     var controlSearcherData =
         new ControlSearcherData {
         Name = expectedName,
         AutomationId = string.Empty,
         Class = string.Empty,
         Value = string.Empty
     };
     
     List<IUiElement> resultList =
         WindowSearcher.ReturnOnlyRightElements(
             new[] { element01, element02, element03, element04 },
             controlSearcherData,
             false,
             true);
     
     MbUnit.Framework.Assert.AreEqual(3, resultList.Count);
     // 20140312
     // MbUnit.Framework.Assert.Exists(resultList, e => e.Current.Name == expectedName); // ??
     MbUnit.Framework.Assert.Exists(resultList, e => e.GetCurrent().Name == expectedName); // ??
 }
예제 #34
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;
 }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable<IUiElement> collection,
            UsualWildcardRegex selector,
            int expectedNumberOfElements)
        {
            // Arrange
            ControlType[] controlTypes =
                new[] { controlType };
            
            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue);
            
            var data =
                new ControlSearcherData {
                ControlType = controlTypes.ConvertControlTypeToStringArray(),
                Name = name,
                AutomationId = automationId,
                Class = className,
                Value = txtValue
            };
            
            Condition condition;
            bool useWildcardOrRegex = true;
            switch (selector) {
                case UsualWildcardRegex.Wildcard:
                    condition =
                        ControlSearcher.GetWildcardSearchCondition(
                            data);
                    useWildcardOrRegex = true;
                    break;
                case UsualWildcardRegex.Regex:
                    condition =
                        ControlSearcher.GetWildcardSearchCondition(
                            data);
                    useWildcardOrRegex = false;
                    break;
            }
            
            // Act
            var resultList = RealCodeCaller.GetResultList_ReturnOnlyRightElements(collection.ToArray(), data, useWildcardOrRegex);
            
            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            string[] controlTypeNames;
            switch (selector) {
                case UsualWildcardRegex.Wildcard:
                    const WildcardOptions options = WildcardOptions.IgnoreCase;
                    // 20140312
//                    WildcardPattern namePattern = new WildcardPattern(name, options);
//                    WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
//                    WildcardPattern classNamePattern = new WildcardPattern(className, options);
//                    WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
                    var namePattern = new WildcardPattern(name, options);
                    var automationIdPattern = new WildcardPattern(automationId, options);
                    var classNamePattern = new WildcardPattern(className, options);
                    var txtValuePattern = new WildcardPattern(txtValue, options);
                    
                    // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.Current.Name));
//                        resultList.All(x => namePattern.IsMatch(x.Current.Name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                        resultList.All(x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.Current.ClassName));
//                        resultList.All(x => classNamePattern.IsMatch(x.Current.ClassName));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                    if (!string.IsNullOrEmpty(name)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.GetCurrent().Name));
                        resultList.All(x => namePattern.IsMatch(x.GetCurrent().Name));
                    }
                    if (!string.IsNullOrEmpty(automationId)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                        resultList.All(x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                    }
                    if (!string.IsNullOrEmpty(className)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                        resultList.All(x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                    }
                    controlTypeNames =
                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                    if (null != controlType) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                        resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    }
                    
                    if (!string.IsNullOrEmpty(txtValue)) {
                        MbUnit.Framework.Assert.ForAll(
                            resultList
                            .Cast<IUiElement>()
                            .ToList<IUiElement>(), x =>
                            {
                                IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                            });
                        
                        resultList.All(
                            x => {
                                IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                            });
                    }
                    break;
                case UsualWildcardRegex.Regex:
                    // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.Name, name));
//                        resultList.All(x => Regex.IsMatch(x.Current.Name, name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                        resultList.All(x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.ClassName, className));
//                        resultList.All(x => Regex.IsMatch(x.Current.ClassName, className));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                    if (!string.IsNullOrEmpty(name)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.GetCurrent().Name, name));
                        resultList.All(x => Regex.IsMatch(x.GetCurrent().Name, name));
                    }
                    if (!string.IsNullOrEmpty(automationId)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                        resultList.All(x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                    }
                    if (!string.IsNullOrEmpty(className)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                        resultList.All(x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                    }
                    controlTypeNames =
                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                    if (null != controlType) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                        resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    }
                    
                    if (!string.IsNullOrEmpty(txtValue)) {
                        MbUnit.Framework.Assert.ForAll(
                            resultList
                            .Cast<IUiElement>()
                            .ToList<IUiElement>(), x =>
                            {
                                IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                return valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue);
                            });
                        Assert.True(
                            resultList.All(
                                x => {
                                    IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                    return valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue);
                                })
                           );
                    }
                    break;
            }
        }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable<IUiElement> collection,
            int expectedNumberOfElements)
        {
            // Arrange
            var data =
                new ControlSearcherData {
                InputObject = new IUiElement[] { CurrentData.CurrentWindow },
                ControlType = (new[] { controlType }).ConvertControlTypeToStringArray(),
                Name = name,
                AutomationId = automationId,
                Class = className,
                Value = txtValue
            };
            
            Condition condition =
                ControlSearcher.GetWildcardSearchCondition(data);
            
            IUiElement element =
                FakeFactory.GetElement_ForFindAll(
                    collection,
                    condition);
            
            // Act
            var resultList = RealCodeCaller.GetResultList_ViaWildcards(element, condition, data);
            
            // Assert
            const WildcardOptions options = WildcardOptions.IgnoreCase;
            // 20140218
            var namePattern = new WildcardPattern(name, options);
            var automationIdPattern = new WildcardPattern(automationId, options);
            var classNamePattern = new WildcardPattern(className, options);
            var txtValuePattern = new WildcardPattern(txtValue, options);
            /*
            WildcardPattern namePattern = new WildcardPattern(name, options);
            WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
            WildcardPattern classNamePattern = new WildcardPattern(className, options);
            WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
            */
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            
            // 20140312
//            if (!string.IsNullOrEmpty(name)) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.Current.Name));
//                resultList.All(x => namePattern.IsMatch(x.Current.Name));
//            }
//            if (!string.IsNullOrEmpty(automationId)) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                resultList.All(x => automationIdPattern.IsMatch(x.Current.AutomationId));
//            }
//            if (!string.IsNullOrEmpty(className)) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.Current.ClassName));
//                resultList.All(x => classNamePattern.IsMatch(x.Current.ClassName));
//            }
//            if (null != controlType) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ControlType == controlType);
//                resultList.All(x => x.Current.ControlType == controlType);
//            }
            if (!string.IsNullOrEmpty(name)) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.GetCurrent().Name));
                resultList.All(x => namePattern.IsMatch(x.GetCurrent().Name));
            }
            if (!string.IsNullOrEmpty(automationId)) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                resultList.All(x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
            }
            if (!string.IsNullOrEmpty(className)) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                resultList.All(x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
            }
            if (null != controlType) {
                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().ControlType == controlType);
                resultList.All(x => x.GetCurrent().ControlType == controlType);
            }
            if (string.IsNullOrEmpty(txtValue)) return;
            
            MbUnit.Framework.Assert.ForAll(
                resultList
                    .Cast<IUiElement>()
                    .ToList<IUiElement>(), x =>
                    {
                        // 20140218
                        var valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        // IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                    });
                
            resultList.All(
                x => {
                        
                        // 20140218
                        var valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        // IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                });
            /*
            if (!string.IsNullOrEmpty(txtValue)) {
                MbUnit.Framework.Assert.ForAll(
                    resultList
                    .Cast<IUiElement>()
                    .ToList<IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                    });
                
                resultList.All(
                    x => {
                        IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                    });
            }
            */
        }
예제 #37
0
        public static List <IUiElement> GetResultList_ViaWildcards_Legacy(IUiElement element, Condition condition, ControlSearcherData data)
        {
            var cmdletDerived = new GetControlCollectionCmdletBase();

            List <IUiElement> resultList =
                cmdletDerived.GetAutomationElementsWithFindAll(
                    element,
                    data,
                    condition,
                    false,
                    false,
                    false,
                    true);

            return(resultList);
        }
 public void NoResults_ZeroInput()
 {
     HasTimeoutCmdletBase cmdlet =
         new HasTimeoutCmdletBase();
     
     var controlSearcherData =
         new ControlSearcherData {
         Name = string.Empty,
         AutomationId = string.Empty,
         Class = string.Empty,
         Value = string.Empty,
         ControlType = new string[] {}
     };
     
     List<IUiElement> resultList =
         WindowSearcher.ReturnOnlyRightElements(
             new UiElement[] {},
             controlSearcherData,
             false,
             true);
     
     MbUnit.Framework.Assert.AreEqual(0, resultList.Count);
 }
예제 #39
0
        internal List <IUiElement> GetWindowCollectionByPid(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            classic.AndCondition conditionsForRecurseSearch = null;

            var elementsByProcessId =
                new List <IUiElement>();

            // 20141001
            // if ((null != data.Name && 0 < data.Name.Count()) ||
            if ((null != data.Name && data.Name.Any()) ||
                !string.IsNullOrEmpty(data.AutomationId) ||
                !string.IsNullOrEmpty(data.Class))
            {
                data.Recurse = true;
            }

            var conditionWindowPaneMenu =
                new classic.OrCondition(
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Window),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Pane),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Menu));

            foreach (int processId in data.ProcessIds)
            {
                conditionsForRecurseSearch =
                    new classic.AndCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ProcessIdProperty,
                            processId),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window));

                var conditionsProcessId =
                    new classic.AndCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ProcessIdProperty,
                            processId),
                        conditionWindowPaneMenu);

                try {
                    if (data.Recurse)
                    {
                        if (data.First)
                        {
                            IUiElement rootWindowElement =
                                rootElement.FindFirst(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != rootWindowElement)
                            {
                                elementsByProcessId.Add(rootWindowElement);
                            }
                        }
                        else
                        {
                            IUiEltCollection rootCollection =
                                rootElement.FindAll(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != rootCollection && 0 < rootCollection.Count)
                            {
                                elementsByProcessId.AddRange(rootCollection.Cast <IUiElement>());
                            }
                        }
                    }
                    else
                    {
                        if (data.First)
                        {
                            IUiElement tempElement =
                                rootElement.FindFirst(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != tempElement)
                            {
                                elementsByProcessId.Add(tempElement);
                            }
                        }
                        else
                        {
                            IUiEltCollection tempCollection =
                                rootElement.FindAll(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != tempCollection && 0 < tempCollection.Count)
                            {
                                elementsByProcessId.AddRange(tempCollection.Cast <IUiElement>());
                            }
                        }
                    }
                } catch (Exception) {
                    // WriteVerbose(
                    //     this,
                    //     "exception: " +
                    //     eGetFirstChildOfRootByProcessId.Message);
                }
            }

            if (!data.Recurse ||
                // 20141001
                // ((null == data.Name || 0 == data.Name.Count()) && string.IsNullOrEmpty(data.AutomationId) &&
                ((null == data.Name || !data.Name.Any()) && string.IsNullOrEmpty(data.AutomationId) &&
                 string.IsNullOrEmpty(data.Class)))
            {
                return(elementsByProcessId);
            }

            var resultList =
                new List <IUiElement>();

            /*
             * List<IUiElement> resultList =
             *  new List<IUiElement>();
             */

            // 20141001
            // if (null != data.Name && 0 < data.Name.Count()) {
            if (null != data.Name && data.Name.Any())
            {
                foreach (string name in data.Name)
                {
                    var controlSearcherData =
                        new ControlSearcherData {
                        Name         = name,
                        AutomationId = data.AutomationId,
                        Class        = data.Class,
                        Value        = string.Empty,
                        ControlType  = new string[] { "Window" }
                    };

                    resultList.AddRange(
                        ReturnOnlyRightElements(
                            elementsByProcessId,
                            controlSearcherData,
                            false,
                            true));
                }
            }
            else
            {
                var controlSearcherData =
                    new ControlSearcherData {
                    Name         = string.Empty,
                    AutomationId = data.AutomationId,
                    Class        = data.Class,
                    Value        = string.Empty,
                    ControlType  = new string[] { "Window" }
                };

                resultList.AddRange(
                    ReturnOnlyRightElements(
                        elementsByProcessId,
                        controlSearcherData,
                        false,
                        true));
            }

            elementsByProcessId = resultList;

            // 20140121
            // never !
            //            if (null != resultList) {
            //                resultList.Clear();
            //                resultList = null;
            //            }

            return(elementsByProcessId);
        }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable <IUiElement> collection,
            UsualWildcardRegex selector,
            int expectedNumberOfElements)
        {
            // Arrange
            ControlType[] controlTypes =
                new[] { controlType };

            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue);

            var data =
                new ControlSearcherData {
                ControlType  = controlTypes.ConvertControlTypeToStringArray(),
                Name         = name,
                AutomationId = automationId,
                Class        = className,
                Value        = txtValue
            };

            Condition condition;
            bool      useWildcardOrRegex = true;

            switch (selector)
            {
            case UsualWildcardRegex.Wildcard:
                condition =
                    ControlSearcher.GetWildcardSearchCondition(
                        data);
                useWildcardOrRegex = true;
                break;

            case UsualWildcardRegex.Regex:
                condition =
                    ControlSearcher.GetWildcardSearchCondition(
                        data);
                useWildcardOrRegex = false;
                break;
            }

            // Act
            var resultList = RealCodeCaller.GetResultList_ReturnOnlyRightElements(collection.ToArray(), data, useWildcardOrRegex);

            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            string[] controlTypeNames;
            switch (selector)
            {
            case UsualWildcardRegex.Wildcard:
                const WildcardOptions options = WildcardOptions.IgnoreCase;
                // 20140312
//                    WildcardPattern namePattern = new WildcardPattern(name, options);
//                    WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
//                    WildcardPattern classNamePattern = new WildcardPattern(className, options);
//                    WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
                var namePattern         = new WildcardPattern(name, options);
                var automationIdPattern = new WildcardPattern(automationId, options);
                var classNamePattern    = new WildcardPattern(className, options);
                var txtValuePattern     = new WildcardPattern(txtValue, options);

                // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.Current.Name));
//                        resultList.All(x => namePattern.IsMatch(x.Current.Name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                        resultList.All(x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.Current.ClassName));
//                        resultList.All(x => classNamePattern.IsMatch(x.Current.ClassName));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                if (!string.IsNullOrEmpty(name))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => namePattern.IsMatch(x.GetCurrent().Name));
                    resultList.All(x => namePattern.IsMatch(x.GetCurrent().Name));
                }
                if (!string.IsNullOrEmpty(automationId))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                    resultList.All(x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                }
                if (!string.IsNullOrEmpty(className))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                    resultList.All(x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                }
                controlTypeNames =
                    controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                if (null != controlType)
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                }

                if (!string.IsNullOrEmpty(txtValue))
                {
                    MbUnit.Framework.Assert.ForAll(
                        resultList
                        .Cast <IUiElement>()
                        .ToList <IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value));
                    });

                    resultList.All(
                        x => {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value));
                    });
                }
                break;

            case UsualWildcardRegex.Regex:
                // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.Name, name));
//                        resultList.All(x => Regex.IsMatch(x.Current.Name, name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                        resultList.All(x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.ClassName, className));
//                        resultList.All(x => Regex.IsMatch(x.Current.ClassName, className));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                if (!string.IsNullOrEmpty(name))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().Name, name));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().Name, name));
                }
                if (!string.IsNullOrEmpty(automationId))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                }
                if (!string.IsNullOrEmpty(className))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                }
                controlTypeNames =
                    controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                if (null != controlType)
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                }

                if (!string.IsNullOrEmpty(txtValue))
                {
                    MbUnit.Framework.Assert.ForAll(
                        resultList
                        .Cast <IUiElement>()
                        .ToList <IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue));
                    });
                    Assert.True(
                        resultList.All(
                            x => {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue));
                    })
                        );
                }
                break;
            }
        }
예제 #41
0
        internal void FilterResultCollectionByWithControlParameter()
        {
            var filteredWindows = new List<IUiElement>();
            bool exitInnerCycle;

            foreach (IUiElement window in ResultCollection) {

                if (!window.IsValid())
                    continue;

                var ControlSearcherData = new ControlSearcherData { InputObject = new UiElement[] { (UiElement)window } };

                exitInnerCycle = false;
                bool addToResultCollection = false;
                foreach (Hashtable ht in (SearcherData as WindowSearcherData).WithControl) {
                    ControlSearcherData.SearchCriteria = new Hashtable[] { ht };

                    try {

                        var controlSearch = AutomationFactory.GetSearcherImpl<ControlSearcher>() as ControlSearcher;

                        List<IUiElement> controlsList = controlSearch.GetElements(ControlSearcherData, 0);

                        if (null == controlsList || 0 == controlsList.Count) {
                            exitInnerCycle = true;
                            addToResultCollection = false;
                            continue;
                        } else {
                            addToResultCollection = true;
                            break;
                        }
                        
                    } catch (Exception) {

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

                ControlSearcherData = null;

                if (addToResultCollection) {
                    filteredWindows.Add(window);
                }
            }

            ResultCollection = filteredWindows;
        }