상속: AutomationIdentifier
 /// <summary>
 /// Get automationelement by name, filtered by classname - mouse click if found
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="automationName">case-insensitive automation name</param>
 /// <param name="controlType"></param>
 /// <param name="controlType2"></param>
 /// <exception cref="ApplicationException">if matching element not found</exception>
 /// <exception cref="ApplicationException">if specified element is not enabled</exception>
 public static void FindElementByNameFilteredByControlTypeAndMouseClick(AutomationElement parent, string automationName, ControlType controlType, ControlType controlType2, TimeSpan mouseClickDelay, TreeScope treeScope)
 {
     FindElementByNameFilteredByControlTypeWithTimeoutAndMouseClick(parent, automationName, controlType, controlType2,
             AddinTestUtility.FindRibbonButtonsTimeout, //findDelay
             mouseClickDelay,
             treeScope);
 }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string searchString,
            IEnumerable<IUiElement> collection,
            int expectedNumberOfElements)
        {
            // Arrange
            string controlTypeString = string.Empty;
            if (null != controlType) {
                controlTypeString = controlType.ProgrammaticName.Substring(12);
            }
            
            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlType, searchString);
            Condition condition =
                ControlSearcher.GetTextSearchCondition(searchString, new string[]{ controlTypeString }, false);
            IUiElement element =
                FakeFactory.GetElement_ForFindAll(
                    collection,
                    condition);
            
            // Act
            var resultList = RealCodeCaller.GetResultList_TextSearch(element, condition);
            
            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Xunit.Assert.Equal(expectedNumberOfElements, resultList.Count);
            if (!string.IsNullOrEmpty(searchString)) {
                MbUnit.Framework.Assert.ForAll(
                    resultList.Cast<IUiElement>().ToList<IUiElement>(),
                    // 20140312
//                    x => x.Current.Name == searchString || x.Current.AutomationId == searchString || x.Current.ClassName == searchString ||
                    x => x.GetCurrent().Name == searchString || x.GetCurrent().AutomationId == searchString || x.GetCurrent().ClassName == searchString ||
                    (null != (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern) && (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString));
                /*
                (null != (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern) ? 
                     // (x.GetCurrentPattern<IValuePattern, ValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString : 
                     (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString : 
                     false));
                */
            }
//            if (null != controlType) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ControlType == controlType);
//            }
            
            Xunit.Assert.Equal(expectedNumberOfElements, resultList.Count);
            if (!string.IsNullOrEmpty(searchString)) {
                resultList.All(
                    // 20140312
                    // x => x.Current.Name == searchString || x.Current.AutomationId == searchString || x.Current.ClassName == searchString ||
                    x => x.GetCurrent().Name == searchString || x.GetCurrent().AutomationId == searchString || x.GetCurrent().ClassName == searchString ||
                    (null != (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern) && (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString));
                /*
                (null != (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern) ?
                     (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString :
                     false));
                */
            }
            
        }
예제 #3
0
        public static AutomationElement FindChildByControlType(this AutomationElement element, ControlType controlType)
        {
            AutomationElement result =
                element.FindChildByCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, controlType));

            return result;
        }
 public static AutomationElement ThrowInvalidOperationExceptionIfNotOf(this AutomationElement automationElement, ControlType controlType)
 {
     if (!automationElement.Current.ControlType.Equals(controlType))
         throw new InvalidOperationException(string.Format("The AutomationElement provided has the ControlType '{0}', which is not a '{1}'.", 
                                                           automationElement.Current.ControlType, controlType));
     return automationElement;
 }
예제 #5
0
        public static AutomationElement getAutomationElement(AutomationElement parent, TreeScope scope, ControlType type, string name)
        {
            var element = parent.FindFirst(scope, new AndCondition(
                new PropertyCondition(AutomationElement.ControlTypeProperty, type),
                new PropertyCondition(AutomationElement.NameProperty, name),
                Automation.ControlViewCondition));

            return element;
        }
예제 #6
0
 public static AutomationElement FindFirstAncestorByControlType(this AutomationElement ae, ControlType className)
 {
     var ancestor = TreeWalker.ControlViewWalker.GetParent(ae);
      for (; ancestor != null && className != ancestor.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty);
     ancestor = TreeWalker.ControlViewWalker.GetParent(ancestor))
      {
      }
      return ancestor;
 }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="automationId"></param>
        /// <param name="className"></param>
        /// <param name="frameworkId"></param>
        /// <param name="controlType"></param>
        /// <returns></returns>
        protected static Condition GetCondition(string name = null, string automationId = null, string className = null, string frameworkId = null, string controlType = null, string fullDescription = null, string accessKey = null)
        {
            var conditionList = new List <Condition>();

            try
            {
                if (!string.IsNullOrEmpty(accessKey) && !accessKey.Contains(Var.Mark.Wildcard) && !accessKey.Contains(Var.Mark.Or) && !accessKey.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.AccessKeyProperty, accessKey));
                }
                if (!string.IsNullOrEmpty(name) && !name.Contains(Var.Mark.Wildcard) && !name.Contains(Var.Mark.Or) && !name.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.NameProperty, name));
                }
                if (!string.IsNullOrEmpty(automationId) && !automationId.Contains(Var.Mark.Wildcard) && !automationId.Contains(Var.Mark.Or) && !automationId.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.AutomationIdProperty, automationId));
                }
                if (!string.IsNullOrEmpty(className) && !className.Contains(Var.Mark.Wildcard) && !className.Contains(Var.Mark.Or) && !className.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.ClassNameProperty, className));
                }
                if (!string.IsNullOrEmpty(fullDescription) && !fullDescription.Contains(Var.Mark.Wildcard) && !fullDescription.Contains(Var.Mark.Or) && !fullDescription.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.FullDescription, fullDescription));
                }
                if (!string.IsNullOrEmpty(frameworkId))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.FrameworkIdProperty, frameworkId));
                }
                if (!string.IsNullOrEmpty(controlType))
                {
                    System.Windows.Automation.ControlType ctrlType = GetControlType(controlType);
                    conditionList.Add(new PropertyCondition(AutomationElement.ControlTypeProperty, ctrlType));
                }
                var condition = new Condition[conditionList.Count];
                //No conditions in, give True Condition
                if (conditionList.Count == 0)
                {
                    return(Condition.TrueCondition);
                }
                for (var i = 0; i < conditionList.Count; i++)
                {
                    condition[i] = conditionList[i];
                }
                if (conditionList.Count == 1)
                {
                    return(condition[0]);
                }
                return(new AndCondition(condition));
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to GetCondition. " + ex.Message);
            }
        }
예제 #8
0
        public static AutomationElement FindElementById(AutomationElement parentElement, string automationID, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

            return parentElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
예제 #9
0
        public static AutomationElement FindWindowByName(AutomationElement rootElement, string name, ControlType type)
        {
            PropertyCondition nameCondition = new PropertyCondition(AutomationElement.NameProperty, name);

            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            AndCondition andCondition = new AndCondition(nameCondition, typeCondition);

            return rootElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
예제 #10
0
        public static AutomationElementCollection FindElementByClassName(AutomationElement parentElement, string className, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.ClassNameProperty, className);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

            return parentElement.FindAll(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
예제 #11
0
        public static Condition ByTypeAndName(ControlType type, String name)
        {
            Condition[] locators =
            {
                new PropertyCondition(AutomationElement.NameProperty, name),
                new PropertyCondition(AutomationElement.ControlTypeProperty, type)
            };

            return new AndCondition(locators);
        }
예제 #12
0
 public static AutomationElement FindInDepth(this AutomationElement root, ControlType type, int levels)
 {
     AutomationElement result = root;
     for (int i = 0; i < levels; i++)
     {
         Thread.Sleep(100);
         result = result.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, type));
     }
     return result;
 }
예제 #13
0
 public ControlDictionaryItem(Type testControlType, ControlType controlType, string className, bool identifiedByClassName, bool isPrimary,
                              bool isExcluded, string frameworkId, bool hasPrimaryChildren)
 {
     this.testControlType = testControlType;
     this.controlType = controlType;
     this.className = className;
     this.identifiedByClassName = identifiedByClassName;
     this.isPrimary = isPrimary;
     this.isExcluded = isExcluded;
     this.frameworkId = frameworkId;
     this.hasPrimaryChildren = hasPrimaryChildren;
 }
예제 #14
0
 public int SetTextValue(String windowName, String objName, String value)
 {
     AutomationElement childHandle = GetObjectHandle(windowName,
         objName);
     if (!utils.IsEnabled(childHandle))
     {
         childHandle = null;
         throw new XmlRpcFaultException(123,
             "Object state is disabled");
     }
     object valuePattern = null;
     try
     {
         if (childHandle.Current.ControlType == ControlType.ComboBox)
         {
             AutomationElement o = null;
             ArrayList objectList = new ArrayList();
             ControlType[] type = new ControlType[1] { ControlType.Edit };
             // NOTE: Using "*" for object name, which returns the first
             // matching Edit control type
             o = utils.InternalGetObjectHandle(childHandle,
                 "*", type, ref objectList);
             if (o != null)
                 childHandle = o;
             objectList = null;
         }
         // Reference: http://msdn.microsoft.com/en-us/library/ms750582.aspx
         if (!childHandle.TryGetCurrentPattern(ValuePattern.Pattern,
             out valuePattern))
         {
             childHandle.SetFocus();
             SendKeys.SendWait(value);
         }
         else
             ((ValuePattern)valuePattern).SetValue(value);
     }
     catch (Exception ex)
     {
         LogMessage(ex);
         if (ex is XmlRpcFaultException)
             throw;
         else
             throw new XmlRpcFaultException(123,
                 "Unhandled exception: " + ex.Message);
     }
     finally
     {
         childHandle = null;
         valuePattern = null;
     }
     return 1;
 }
예제 #15
0
 private AutomationElement GetObjectHandle(string windowName,
     string objName)
 {
     ControlType[] type = new ControlType[1] { ControlType.ScrollBar };
     try
     {
         return utils.GetObjectHandle(windowName, objName, type);
     }
     finally
     {
         type = null;
     }
 }
예제 #16
0
 /// <summary>
 /// This method gets the list of ChildElements of the control type in the Window.
 /// </summary>
 /// <param name="type">Control type</param>       
 public static bool GetChildElement(ControlType type)
 {
     try
     {
         CommonHelperMethods.GetElement(AutomationElement.RootElement, type);
         return true;
     }
     catch (ElementNotAvailableException ex)
     {
         Console.WriteLine(ex);
         return false;
     }
 }
예제 #17
0
 private AutomationElement GetObjectHandle(string windowName,
     string objName)
 {
     ControlType[] type = new ControlType[3] { ControlType.ComboBox,
         ControlType.ListItem, ControlType.List/*, ControlType.Text */ };
     try
     {
         return utils.GetObjectHandle(windowName, objName, type);
     }
     finally
     {
         type = null;
     }
 }
예제 #18
0
 /// <summary>
 /// This method returns an element searched by its control type from the tree.
 /// </summary>
 /// <param name="root">Root Element of the control</param>
 /// <param name="controlType">Control Type of the element</param>
 /// <returns>Automation Element of teh control</returns>
 public static AutomationElement GetElement(AutomationElement root, ControlType controlType)
 {
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (controlType == null)
     {
         throw new ArgumentNullException("controlType");
     }
     else
     {
         PropertyCondition condType = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
         return root.FindFirst(TreeScope.Descendants, condType);
     }
 }
예제 #19
0
 private AutomationElement GetObjectHandle(string windowName,
     string objName)
 {
     // Pane added for a bug in QT
     // Ref: https://cobra.codeplex.com/discussions/450296
     ControlType[] type = new ControlType[4] { ControlType.Edit,
         ControlType.Document, ControlType.ComboBox, ControlType.Pane };
     try
     {
         return utils.GetObjectHandle(windowName, objName, type);
     }
     finally
     {
         type = null;
     }
 }
예제 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="AutomationId"></param>
        /// <param name="ClassName"></param>
        /// <param name="FrameworkId"></param>
        /// <param name="ControlType"></param>
        /// <returns></returns>
        protected static System.Windows.Automation.Condition GetCondition(string Name = null, string AutomationId = null, string ClassName = null, string FrameworkId = null, string ControlType = null)
        {
            List <Condition> conditionList = new List <Condition>();

            try
            {
                if (!String.IsNullOrEmpty(Name) && !Name.Contains(Var.Mark.Wildcard) && !Name.Contains(Var.Mark.Or) && !Name.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.NameProperty, Name));
                }
                if (!String.IsNullOrEmpty(AutomationId) && !AutomationId.Contains(Var.Mark.Wildcard) && !AutomationId.Contains(Var.Mark.Or) && !AutomationId.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.AutomationIdProperty, AutomationId));
                }
                if (!String.IsNullOrEmpty(ClassName) && !ClassName.Contains(Var.Mark.Wildcard) && !ClassName.Contains(Var.Mark.Or) && !ClassName.Contains(Var.Mark.And))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.ClassNameProperty, ClassName));
                }
                if (!String.IsNullOrEmpty(FrameworkId))
                {
                    conditionList.Add(new PropertyCondition(AutomationElement.FrameworkIdProperty, FrameworkId));
                }
                if (!String.IsNullOrEmpty(ControlType))
                {
                    System.Windows.Automation.ControlType ctrlType = GetControlType(ControlType);
                    conditionList.Add(new PropertyCondition(AutomationElement.ControlTypeProperty, ctrlType));
                }
                Condition[] condition = new Condition[conditionList.Count];
                for (int i = 0; i < conditionList.Count; i++)
                {
                    condition[i] = conditionList[i];
                }
                if (conditionList.Count == 1)
                {
                    return(condition[0]);
                }
                else if (conditionList.Count == 0)
                {
                    return(null);
                }
                return(new AndCondition(condition));
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to GetCondition. " + ex.Message);
            }
        }
예제 #21
0
파일: Tree.cs 프로젝트: Chingliu/cobra
 public int DoesRowExist(String windowName, String objName,
     String text, bool partialMatch = false)
 {
     if (String.IsNullOrEmpty(text))
     {
         LogMessage("Argument cannot be empty.");
         return 0;
     }
     ControlType[] type;
     AutomationElement childHandle;
     AutomationElement elementItem;
     try
     {
         childHandle = GetObjectHandle(windowName,
             objName, null, false);
         if (!utils.IsEnabled(childHandle))
         {
             childHandle = null;
             LogMessage("Object state is disabled");
             return 0;
         }
         childHandle.SetFocus();
         type = new ControlType[4] { ControlType.TreeItem,
             ControlType.ListItem, ControlType.DataItem,
             ControlType.Custom };
         if (partialMatch)
             text += "*";
         elementItem = utils.GetObjectHandle(childHandle,
             text, type, false);
         if (elementItem != null)
         {
             return 1;
         }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
     }
     finally
     {
         type = null;
         childHandle = elementItem = null;
     }
     return 0;
 }
예제 #22
0
 private AutomationElement GetObjectHandle(string windowName,
     string objName, ControlType[] type = null, bool waitForObj = true)
 {
     if (type == null)
         type = new ControlType[6] { ControlType.Tree,
             ControlType.List, ControlType.Table,
             ControlType.DataItem, ControlType.ListItem,
             ControlType.TreeItem };
     try
     {
         return utils.GetObjectHandle(windowName,
             objName, type, waitForObj);
     }
     finally
     {
         type = null;
     }
 }
 private IUiElement TestElementsCollectionOfCertainType(ControlType controlType, out IUiElement[] elements)
 {
     // Arrange
     IUiElement[] elementsArray =
         new[] {
             FakeFactory.GetAutomationElementExpected(controlType, string.Empty, string.Empty, string.Empty, string.Empty),
             FakeFactory.GetAutomationElementExpected(controlType, string.Empty, string.Empty, string.Empty, string.Empty),
             FakeFactory.GetAutomationElementExpected(controlType, string.Empty, string.Empty, string.Empty, string.Empty)
         };
     elements = elementsArray;
     IUiElement element =
         FakeFactory.GetElement_ForFindAll(
             elements,
             new PropertyCondition(
                 AutomationElement.ControlTypeProperty,
                 controlType));
     
     return element;
 }
예제 #24
0
 /// <summary>
 /// Уточнить поиск по ControlType через логическое И.
 /// </summary>
 /// <param name="value">
 /// Тип элемента.
 /// </param>
 public By AndType(ControlType value)
 {
     this.And(AutomationElement.ControlTypeProperty, value);
     return this;
 }
 public static AutomationSearchCondition GetWindowSearchCondition(int processId, ControlType controlType)
 {
     AutomationSearchCondition windowSearchCondition = ByControlType(controlType);
     if (processId > 0) windowSearchCondition.WithProcessId(processId);
     return windowSearchCondition;
 }
 public static AutomationSearchCondition ByControlType(ControlType controlType)
 {
     var automationSearchCondition = new AutomationSearchCondition();
     automationSearchCondition.OfControlType(controlType);
     return automationSearchCondition;
 }
 public virtual AutomationSearchCondition OfControlType(ControlType controlType)
 {
     conditions.Add(new PropertyCondition(AutomationElement.ControlTypeProperty, controlType));
     return this;
 }
예제 #28
0
파일: Utils.cs 프로젝트: sganesh/cobra
 private AutomationElement InternalGetWindowHandle(String windowName,
     ControlType[] type = null)
 {
     String s;
     int index;
     String actualString;
     AutomationElement element;
     CurrentObjInfo currObjInfo;
     ObjInfo objInfo = new ObjInfo(false);
     ArrayList objectList = new ArrayList();
     // Trying to mimic python fnmatch.translate
     String tmp = Regex.Replace(windowName, @"\*", @".*");
     tmp = Regex.Replace(tmp, @"\\", @"\\");
     tmp = Regex.Replace(tmp, "( |\r|\n)", "");
     tmp = @"\A(?ms)" + tmp + @"\Z(?ms)";
     //tmp += @"\Z(?ms)";
     Regex rx = new Regex(tmp, RegexOptions.Compiled |
         RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline |
         RegexOptions.CultureInvariant);
     List<AutomationElement> windowTmpList = new List<AutomationElement>();
     InternalTreeWalker w = new InternalTreeWalker();
     try
     {
         foreach (AutomationElement e in windowList)
         {
             try
             {
                 currObjInfo = objInfo.GetObjectType(e);
                 s = e.Current.Name;
                 if (s != null)
                     s = Regex.Replace(s, "( |\r|\n)", "");
                 if (s == null || s.Length == 0)
                 {
                     // txt0, txt1
                     actualString = currObjInfo.objType +
                         currObjInfo.objCount;
                 }
                 else
                 {
                     // txtName, txtPassword
                     actualString = currObjInfo.objType + s;
                     index = 1;
                     while (true)
                     {
                         if (objectList.IndexOf(actualString) < 0)
                         {
                             // Object doesn't exist, assume this is the first
                             // element with the name and type
                             break;
                         }
                         actualString = currObjInfo.objType + s + index;
                         index++;
                     }
                 }
                 LogMessage("Window: " + actualString + " : " + tmp);
                 objectList.Add(actualString);
                 // FIXME: Handle dlg0 as in Linux
                 if ((s != null && rx.Match(s).Success) ||
                     rx.Match(actualString).Success)
                 {
                     if (type == null)
                     {
                         LogMessage(windowName + " - Window found");
                         w = null;
                         rx = null;
                         objectList = null;
                         windowTmpList = null;
                         return e;
                     }
                     else
                     {
                         foreach (ControlType t in type)
                         {
                             if (debug)
                                 LogMessage((t == e.Current.ControlType) +
                                     " : " + e.Current.ControlType.ProgrammaticName);
                             if (t == e.Current.ControlType)
                             {
                                 w = null;
                                 rx = null;
                                 objectList = null;
                                 windowTmpList = null;
                                 return e;
                             }
                         }
                         LogMessage("type doesn't match !!!!!!!!!!!!!!");
                     }
                 }
             }
             catch (ElementNotAvailableException ex)
             {
                 // Don't alter the current list, remove it later
                 windowTmpList.Add(e);
                 LogMessage(ex);
             }
             catch (Exception ex)
             {
                 // Don't alter the current list, remove it later
                 windowTmpList.Add(e);
                 LogMessage(ex);
             }
         }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
     }
     try
     {
         foreach (AutomationElement e in windowTmpList)
             try
             {
                 // Remove element from the list
                 windowList.Remove(e);
             }
             catch (Exception ex)
             {
                 LogMessage(ex);
             }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
     }
     windowTmpList = null;
     objectList.Clear();
     objInfo = new ObjInfo(false);
     element = w.walker.GetFirstChild(AutomationElement.RootElement);
     try
     {
         while (null != element)
         {
             currObjInfo = objInfo.GetObjectType(element);
             s = element.Current.Name;
             if (s != null)
                 s = Regex.Replace(s, "( |\r|\n)", "");
             if (s == null || s == "")
             {
                 // txt0, txt1
                 actualString = currObjInfo.objType +
                     currObjInfo.objCount;
             }
             else
             {
                 // txtName, txtPassword
                 actualString = currObjInfo.objType + s;
                 index = 1;
                 while (true)
                 {
                     if (objectList.IndexOf(actualString) < 0)
                     {
                         // Object doesn't exist, assume this is the first
                         // element with the name and type
                         break;
                     }
                     actualString = currObjInfo.objType + s + index;
                     index++;
                 }
             }
             LogMessage("Window: " + actualString + " : " + tmp);
             objectList.Add(actualString);
             // FIXME: Handle dlg0 as in Linux
             if ((s != null && rx.Match(s).Success) ||
                 rx.Match(actualString).Success)
             {
                 if (type == null)
                 {
                     LogMessage(windowName + " - Window found");
                     return element;
                 }
                 else
                 {
                     foreach (ControlType t in type)
                     {
                         if (debug)
                             LogMessage((t == element.Current.ControlType) +
                                 " : " + element.Current.ControlType.ProgrammaticName);
                         if (t == element.Current.ControlType)
                         {
                             return element;
                         }
                     }
                     LogMessage("type doesn't match !!!!!!!!!!!!!!");
                 }
             }
             element = w.walker.GetNextSibling(element);
         }
         element = w.walker.GetFirstChild(
             AutomationElement.RootElement);
         // Reset object info
         objInfo = new ObjInfo(false);
         objectList.Clear();
         AutomationElement subChild;
         while (null != element)
         {
             subChild = w.walker.GetFirstChild(
                 element);
             while (subChild != null)
             {
                 if (subChild.Current.Name != null)
                 {
                     currObjInfo = objInfo.GetObjectType(subChild);
                     s = subChild.Current.Name;
                     if (s != null)
                         s = Regex.Replace(s, "( |\r|\n)", "");
                     if (s == null || s == "")
                     {
                         // txt0, txt1
                         actualString = currObjInfo.objType +
                             currObjInfo.objCount;
                     }
                     else
                     {
                         // txtName, txtPassword
                         actualString = currObjInfo.objType + s;
                         index = 1;
                         while (true)
                         {
                             if (objectList.IndexOf(actualString) < 0)
                             {
                                 // Object doesn't exist, assume this is the first
                                 // element with the name and type
                                 break;
                             }
                             actualString = currObjInfo.objType + s + index;
                             index++;
                         }
                     }
                     LogMessage("SubWindow: " + actualString + " : " + tmp);
                     if ((s != null && rx.Match(s).Success) ||
                         rx.Match(actualString).Success)
                     {
                         if (type == null)
                         {
                             LogMessage(windowName + " - Window found");
                             return subChild;
                         }
                         else
                         {
                             foreach (ControlType t in type)
                             {
                                 if (debug)
                                     LogMessage((t == subChild.Current.ControlType) +
                                         " : " + subChild.Current.ControlType.ProgrammaticName);
                                 if (t == subChild.Current.ControlType)
                                 {
                                     LogMessage(windowName + " - Window found");
                                     return subChild;
                                 }
                             }
                             LogMessage("type doesn't match !!!!!!!!!!!!!!");
                         }
                     }
                 }
                 subChild = w.walker.GetNextSibling(subChild);
             }
             element = w.walker.GetNextSibling(element);
         }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
     }
     finally
     {
         w = null;
         rx = null;
         objectList = null;
     }
     // Unable to find window
     return null;
 }
예제 #29
0
파일: Utils.cs 프로젝트: sganesh/cobra
        private AutomationElement InternalGetObjectHandle(AutomationElement childHandle,
            String objName, ControlType[] type, ref ArrayList objectList)
        {
            if (childHandle == null)
            {
                LogMessage("InternalGetObjectHandle: Child handle NULL");
                return null;
            }
            int index;
            String s = null;
            AutomationElement element;
            CurrentObjInfo currObjInfo;
            String actualString = null;
            ObjInfo objInfo = new ObjInfo(false);

            InternalTreeWalker w = new InternalTreeWalker();
            // Trying to mimic python fnmatch.translate
            String tmp = Regex.Replace(objName, @"( |:|\.|_|\r|\n|<|>)", "");
            tmp = Regex.Replace(tmp, @"\*", @".*");
            tmp = Regex.Replace(tmp, @"\\", @"\\");
            tmp = Regex.Replace(tmp, @"\(", @"\(");
            tmp = Regex.Replace(tmp, @"\)", @"\)");
            tmp = @"\A(?ms)" + tmp + @"\Z(?ms)";
            // This fails for some reason, commenting out for now
            //tmp += @"\Z(?ms)";
            Regex rx = new Regex(tmp, RegexOptions.Compiled |
                RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline |
                RegexOptions.CultureInvariant);
            try
            {
                element = childHandle;
                while (null != element)
                {
                    s = element.Current.Name;
                    currObjInfo = objInfo.GetObjectType(element);
                    if (s == null)
                    {
                        LogMessage("Current object Name is null");
                    }
                    else
                    {
                        s = s.ToString();
                        if (debug)
                            LogMessage("Obj name: " + s + " : " +
                                element.Current.ControlType.ProgrammaticName);
                        if (element.Current.ControlType == ControlType.MenuItem)
                        { // Do this only for menuitem type
                            // Split keyboard shortcut, as that might not be
                            // part of user provided object name
                            string[] tmpStrArray = Regex.Split(s, @"\t");
                            LogMessage("Menuitem shortcut length: " +
                                tmpStrArray.Length);
                            if (tmpStrArray.Length > 1)
                                // Keyboard shortcut found,
                                // just take first element from array
                                s = tmpStrArray[0];
                            tmpStrArray = null;
                        }
                    }
                    if (currObjInfo.objType != null)
                    {
                        if (s != null)
                            s = Regex.Replace(s, @"( |\t|:|\.|_|\r|\n|<|>)", "");
                        if (s == null || s.Length == 0)
                        {
                            // txt0, txt1
                            actualString = currObjInfo.objType +
                                currObjInfo.objCount;
                        }
                        else
                        {
                            // txtName, txtPassword
                            actualString = currObjInfo.objType + s;
                            LogMessage("###" + actualString + "###");
                            index = 1;
                            while (true)
                            {
                                if (objectList.IndexOf(actualString) < 0)
                                {
                                    // Object doesn't exist, assume this is the first
                                    // element with the name and type
                                    break;
                                }
                                actualString = currObjInfo.objType + s + index;
                                index++;
                            }
                        }
                        if (debug)
                        {
                            LogMessage(objName + " : " + actualString + " : " + s + " : " +
                                tmp);
                            LogMessage((s != null && rx.Match(s).Success) + " : " +
                                (rx.Match(actualString).Success));
                        }
                        objectList.Add(actualString);
                    }
                    if ((s != null && rx.Match(s).Success) ||
                        (actualString != null && rx.Match(actualString).Success))
                    {
                        if (type == null)
                            return element;
                        else
                        {
                            foreach (ControlType t in type)
                            {
                                if (debug)
                                    LogMessage((t == element.Current.ControlType) +
                                        " : " + element.Current.ControlType.ProgrammaticName);
                                if (t == element.Current.ControlType)
                                    return element;
                            }
                            LogMessage("type doesn't match !!!!!!!!!!!!!!");
                        }
                    }
                    // If any subchild exist for the current element navigate to it
                    AutomationElement subChild = InternalGetObjectHandle(
                        w.walker.GetFirstChild(element),
                        objName, type, ref objectList);
                    if (subChild != null)
                    {
                        // Object found, don't loop further
                        return subChild;
                    }
                    element = w.walker.GetNextSibling(element);
                }
            }
            catch (ElementNotAvailableException ex)
            {
                LogMessage(ex);
            }
            catch (Exception ex)
            {
                LogMessage(ex);
            }
            finally
            {
                w = null;
                rx = null;
            }
            return null;
        }
예제 #30
0
파일: Utils.cs 프로젝트: sganesh/cobra
        internal bool InternalGetObjectList(AutomationElement windowHandle,
            ref ArrayList objectList, ref Hashtable objectHT,
            ref string matchedKey, bool needAll = false,
            string objName = null, string parentName = null,
            ControlType type = null)
        {
            if (windowHandle == null)
            {
                LogMessage("Invalid window handle");
                return false;
            }
            int index;
            Regex rx = null;
            String s = null;
            ObjInfo objInfo = new ObjInfo(false);
            String actualString = null;
            CurrentObjInfo currObjInfo;
            Hashtable propertyHT;
            // Trying to mimic python fnmatch.translate
            String tmp = null;

            InternalTreeWalker w = new InternalTreeWalker();
            if (objName != null)
            {
                tmp = Regex.Replace(objName, @"\*", @".*");
                tmp = Regex.Replace(tmp, @"( |:|\.|_|\r|\n|<|>)", "");
                tmp = Regex.Replace(tmp, @"\(", @"\(");
                tmp = Regex.Replace(tmp, @"\)", @"\)");
                //tmp += @"\Z(?ms)";
                rx = new Regex(tmp, RegexOptions.Compiled |
                    RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline |
                    RegexOptions.CultureInvariant);
            }
            try
            {
                AutomationElement element = windowHandle;
                while (null != element)
                {
                    s = element.Current.Name;
                    currObjInfo = objInfo.GetObjectType(element);
                    if (s == null)
                    {
                        LogMessage("Current object Name is null");
                    }
                    else
                    {
                        s = s.ToString();
                        if (debug)
                            LogMessage("Obj name: " + s + " : " +
                                element.Current.ControlType.ProgrammaticName);
                    }
                    actualString = null;
                    if (s != null)
                        s = Regex.Replace(s, @"( |\t|:|\.|_|\r|\n|<|>)", "");
                    if (s == null || s.Length == 0)
                    {
                        // txt0, txt1
                        actualString = currObjInfo.objType + currObjInfo.objCount;
                    }
                    else
                    {
                        // txtName, txtPassword
                        actualString = currObjInfo.objType + s;
                        index = 1;
                        while (true)
                        {
                            if (objectList.IndexOf(actualString) < 0)
                            {
                                // Object doesn't exist, assume this is the first
                                // element with the name and type
                                break;
                            }
                            actualString = currObjInfo.objType + s + index;
                            index++;
                        }
                    }
                    if (type == null || type == element.Current.ControlType)
                        // Add if ControlType is null
                        // or only matching type, if available
                        objectList.Add(actualString);
                    if (objName != null || needAll)
                    {
                        //needAll - Required for GetChild
                        propertyHT = new Hashtable();
                        propertyHT.Add("key", actualString);
                        try
                        {
                            LogMessage(element.Current.LocalizedControlType);
                            string className = element.Current.LocalizedControlType;
                            if (element.Current.ControlType == ControlType.Button)
                                // For LDTP compatibility
                                className = "push_button";
                            propertyHT.Add("class",
                                Regex.Replace(className, " ", "_"));
                        }
                        catch (Exception ex)
                        {
                            LogMessage(ex);
                            propertyHT.Add("class",
                                element.Current.ControlType.ProgrammaticName);
                        }
                        propertyHT.Add("parent", parentName);
                        //propertyHT.Add("child_index", element.Current);
                        ArrayList childrenList = new ArrayList();
                        propertyHT.Add("children", childrenList);
                        // Check if parent exists
                        if (parentName != null && parentName.Length > 0 &&
                            objectHT[parentName] != null)
                        {
                            LogMessage("parentName NOT NULL");
                            // Add current child to the parent
                            ((ArrayList)((Hashtable)objectHT[parentName])["children"]).Add(actualString);
                        }
                        else
                            LogMessage("parentName NULL");
                        propertyHT.Add("obj_index",
                            currObjInfo.objType + "#" + currObjInfo.objCount);
                        if (s != null)
                            propertyHT.Add("label", element.Current.Name);
                        // Following 2 properties exist in Linux
                        //propertyHT.Add("label_by", s == null ? "" : s);
                        //propertyHT.Add("description", element.Current.DescribedBy);
                        if (element.Current.AcceleratorKey != "")
                            propertyHT.Add("key_binding",
                                element.Current.AcceleratorKey);
                        // Add individual property to object property
                        objectHT.Add(actualString, propertyHT);
                        if (debug && rx != null)
                        {
                            LogMessage(objName + " : " + actualString + " : " + s
                                + " : " + tmp);
                            LogMessage((s != null && rx.Match(s).Success) + " : " +
                                (actualString != null && rx.Match(actualString).Success));
                        }
                        if ((s != null && rx != null && rx.Match(s).Success) ||
                        (actualString != null && rx != null && rx.Match(actualString).Success))
                        {
                            matchedKey = actualString;
                            LogMessage("String matched: " + needAll);
                            if (!needAll)
                                return true;
                        }
                    }

                    // If any subchild exist for the current element navigate to it
                    if (InternalGetObjectList(w.walker.GetFirstChild(element),
                        ref objectList, ref objectHT, ref matchedKey,
                        needAll, objName, actualString))
                        return true;
                    element = w.walker.GetNextSibling(element);
                }
            }
            catch (ElementNotAvailableException ex)
            {
                LogMessage("Exception: " + ex);
            }
            catch (Exception ex)
            {
                LogMessage("Exception: " + ex);
            }
            finally
            {
                w = null;
                rx = null;
                propertyHT = null;
            }
            return false;
        }
예제 #31
0
파일: Utils.cs 프로젝트: sganesh/cobra
        internal int InternalCheckObject(string windowName, string objName,
					 string actionType)
        {
            if (String.IsNullOrEmpty(windowName) ||
                String.IsNullOrEmpty(objName) ||
                String.IsNullOrEmpty(actionType))
            {
                throw new XmlRpcFaultException(123, "Argument cannot be empty.");
            }
            AutomationElement windowHandle = GetWindowHandle(windowName);
            if (windowHandle == null)
            {
                throw new XmlRpcFaultException(123,
                    "Unable to find window: " + windowName);
            }
            ControlType[] type = new ControlType[2] { ControlType.CheckBox,
                ControlType.RadioButton };
            AutomationElement childHandle = GetObjectHandle(windowHandle,
                objName, type, true);
            windowHandle = null;
            if (childHandle == null)
            {
                throw new XmlRpcFaultException(123,
                    "Unable to find Object: " + objName);
            }
            AutomationPattern[] patterns = childHandle.GetSupportedPatterns();
            Object pattern = null;
            try
            {
                if (childHandle.TryGetCurrentPattern(TogglePattern.Pattern,
                    out pattern))
                {
                    switch (actionType)
                    {
                        case "VerifyCheck":
                            if (((TogglePattern)pattern).Current.ToggleState == ToggleState.On)
                                return 1;
                            return 0;
                        case "VerifyUncheck":
                            if (((TogglePattern)pattern).Current.ToggleState == ToggleState.Off)
                                return 1;
                            return 0;
                        case "Check":
                            if (((TogglePattern)pattern).Current.ToggleState == ToggleState.On)
                            {
                                LogMessage("Checkbox / Radio button already checked");
                                return 1;
                            }
                            break;
                        case "UnCheck":
                            if (((TogglePattern)pattern).Current.ToggleState == ToggleState.Off)
                            {
                                LogMessage("Checkbox / Radio button already unchecked");
                                return 1;
                            }
                            break;
                        default:
                            throw new XmlRpcFaultException(123, "Unsupported actionType");
                    }
                    Object invoke = null;
                    childHandle.SetFocus();
                    if (childHandle.TryGetCurrentPattern(InvokePattern.Pattern,
                                     out invoke))
                        ((InvokePattern)invoke).Invoke();
                    else
                        ((TogglePattern)pattern).Toggle();
                    invoke = null;
                    return 1;
                }
                else if (childHandle.TryGetCurrentPattern(SelectionItemPattern.Pattern,
                    out pattern))
                {
                    switch (actionType)
                    {
                        case "VerifyCheck":
                            if (((SelectionItemPattern)pattern).Current.IsSelected)
                                return 1;
                            return 0;
                        case "VerifyUncheck":
                            if (((SelectionItemPattern)pattern).Current.IsSelected == false)
                                return 1;
                            return 0;
                        case "Check":
                            childHandle.SetFocus();
                            ((SelectionItemPattern)pattern).Select();
                            return 1;
                    }
                }
            }
            catch (Exception ex)
            {
                LogMessage(ex);
                if (ex is XmlRpcFaultException)
                    throw;
                else
                    throw new XmlRpcFaultException(123,
                        "Unhandled exception: " + ex.Message);
            }
            finally
            {
                pattern = null;
                childHandle = null;
            }
            LogMessage("Unsupported pattern to perform action");
            throw new XmlRpcFaultException(123,
                "Unsupported pattern to perform action");
        }
예제 #32
0
파일: Utils.cs 프로젝트: sganesh/cobra
 internal AutomationElement GetWindowHandle(String windowName,
     bool waitForObj = true, ControlType[] type = null)
 {
     AutomationElement o = null;
     if (String.IsNullOrEmpty(windowName))
     {
         LogMessage("Invalid window name");
         return o;
     }
     int retry = waitForObj ? objectTimeOut : 1;
     // For debugging use the following value
     //int retry = waitForObj ? 1 : 1;
     for (int i = 0; i < retry; i++)
     {
         Thread thread = new Thread(delegate()
         {
             o = InternalGetWindowHandle(windowName, type);
         });
         thread.Start();
         // Wait 30 seconds (30 seconds * 1000 milli seconds)
         if (!thread.Join(30000))
         {
             // Windows automation library hanged
             LogMessage("WARNING: Thread aborting, as the program" +
             " unable to find window within 30 seconds");
             // This is an unsafe operation so use as a last resort.
             // Aborting only the current thread
             thread.Abort();
         }
         else
         {
             // Collect all generations of memory.
             GC.Collect();
             if (o != null)
             {
                 try
                 {
                     LogMessage("object is non null: " + o.Current.Name);
                 }
                 catch (System.Runtime.InteropServices.COMException ex)
                 {
                     // Noticed this with Notepad
                     LogMessage("Error HRESULT E_FAIL has been" +
                         " returned from a call to a COM component.");
                     LogMessage(ex.StackTrace);
                     continue;
                 }
                 return o;
             }
         }
     }
     return o;
 }
예제 #33
0
 //Required patterns, never supported patterns and required properties are set to an empty array
 internal static ControlType Register(AutomationIdentifierConstants.ControlTypes id, string programmaticName, string stId)
 {
     return(ControlType.Register(id, programmaticName, stId, new AutomationProperty[0], new AutomationPattern[0], new AutomationPattern[0][]));
 }
예제 #34
0
        static ControlType()
        {
            Button = new ControlType (ButtonId, "ControlType.Button");
            Button.localizedControlType = Catalog.GetString("button");
            Button.neverSupportedPatterns = new AutomationPattern [] {};
            Button.requiredProperties = new AutomationProperty [] {};
            Button.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    InvokePatternIdentifiers.Pattern}};

            Calendar = new ControlType (CalendarId, "ControlType.Calendar");
            Calendar.localizedControlType = Catalog.GetString("calendar");
            Calendar.neverSupportedPatterns = new AutomationPattern [] {};
            Calendar.requiredProperties = new AutomationProperty [] {};
            Calendar.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    GridPatternIdentifiers.Pattern,
                    ValuePatternIdentifiers.Pattern,
                    SelectionPatternIdentifiers.Pattern}};

            CheckBox = new ControlType (CheckBoxId, "ControlType.CheckBox");
            CheckBox.localizedControlType = Catalog.GetString("check box");
            CheckBox.neverSupportedPatterns = new AutomationPattern [] {};
            CheckBox.requiredProperties = new AutomationProperty [] {};
            CheckBox.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    TogglePatternIdentifiers.Pattern}};

            ComboBox = new ControlType (ComboBoxId, "ControlType.ComboBox");
            ComboBox.localizedControlType = Catalog.GetString("combo box");
            ComboBox.neverSupportedPatterns = new AutomationPattern [] {};
            ComboBox.requiredProperties = new AutomationProperty [] {};
            ComboBox.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    SelectionPatternIdentifiers.Pattern,
                    ExpandCollapsePatternIdentifiers.Pattern}};

            Custom = new ControlType (CustomId, "ControlType.Custom");
            Custom.localizedControlType = Catalog.GetString("custom");
            Custom.neverSupportedPatterns = new AutomationPattern [] {};
            Custom.requiredProperties = new AutomationProperty [] {};
            Custom.requiredPatternSets = new AutomationPattern [] [] {};

            DataGrid = new ControlType (DataGridId, "ControlType.DataGrid");
            DataGrid.localizedControlType = Catalog.GetString("datagrid");
            DataGrid.neverSupportedPatterns = new AutomationPattern [] {};
            DataGrid.requiredProperties = new AutomationProperty [] {};
            DataGrid.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    SelectionPatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    GridPatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    TablePatternIdentifiers.Pattern}};

            DataItem = new ControlType (DataItemId, "ControlType.DataItem");
            DataItem.localizedControlType = Catalog.GetString("dataitem");
            DataItem.neverSupportedPatterns = new AutomationPattern [] {};
            DataItem.requiredProperties = new AutomationProperty [] {};
            DataItem.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    SelectionItemPatternIdentifiers.Pattern}
            };

            Document = new ControlType (DocumentId, "ControlType.Document");
            Document.localizedControlType = Catalog.GetString("document");
            Document.neverSupportedPatterns = new AutomationPattern [] {
                ValuePatternIdentifiers.Pattern
            };
            Document.requiredProperties = new AutomationProperty [] {};
            Document.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    ScrollPatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    TextPatternIdentifiers.Pattern}
            };

            Edit = new ControlType (EditId, "ControlType.Edit");
            Edit.localizedControlType = Catalog.GetString("edit");
            Edit.neverSupportedPatterns = new AutomationPattern [] {};
            Edit.requiredProperties = new AutomationProperty [] {};
            Edit.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    ValuePatternIdentifiers.Pattern}
            };

            Group = new ControlType (GroupId, "ControlType.Group");
            Group.localizedControlType = Catalog.GetString("group");
            Group.neverSupportedPatterns = new AutomationPattern [] {};
            Group.requiredProperties = new AutomationProperty [] {};
            Group.requiredPatternSets = new AutomationPattern [] [] {};

            HeaderItem = new ControlType (HeaderItemId, "ControlType.HeaderItem");
            HeaderItem.localizedControlType = Catalog.GetString("header item");
            HeaderItem.neverSupportedPatterns = new AutomationPattern [] {};
            HeaderItem.requiredProperties = new AutomationProperty [] {};
            HeaderItem.requiredPatternSets = new AutomationPattern [] [] {};

            Header = new ControlType (HeaderId, "ControlType.Header");
            Header.localizedControlType = Catalog.GetString("header");
            Header.neverSupportedPatterns = new AutomationPattern [] {};
            Header.requiredProperties = new AutomationProperty [] {};
            Header.requiredPatternSets = new AutomationPattern [] [] {};

            Hyperlink = new ControlType (HyperlinkId, "ControlType.Hyperlink");
            Hyperlink.localizedControlType = Catalog.GetString("hyperlink");
            Hyperlink.neverSupportedPatterns = new AutomationPattern [] {};
            Hyperlink.requiredProperties = new AutomationProperty [] {};
            Hyperlink.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    InvokePatternIdentifiers.Pattern}
            };

            Image = new ControlType (ImageId, "ControlType.Image");
            Image.localizedControlType = Catalog.GetString("image");
            Image.neverSupportedPatterns = new AutomationPattern [] {};
            Image.requiredProperties = new AutomationProperty [] {};
            Image.requiredPatternSets = new AutomationPattern [] [] {};

            ListItem = new ControlType (ListItemId, "ControlType.ListItem");
            ListItem.localizedControlType = Catalog.GetString("list item");
            ListItem.neverSupportedPatterns = new AutomationPattern [] {};
            ListItem.requiredProperties = new AutomationProperty [] {};
            ListItem.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    SelectionItemPatternIdentifiers.Pattern}
            };

            List = new ControlType (ListId, "ControlType.List");
            List.localizedControlType = Catalog.GetString("list view");
            List.neverSupportedPatterns = new AutomationPattern [] {};
            List.requiredProperties = new AutomationProperty [] {};
            List.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    SelectionPatternIdentifiers.Pattern,
                    TablePatternIdentifiers.Pattern,
                    GridPatternIdentifiers.Pattern,
                    MultipleViewPatternIdentifiers.Pattern}
            };

            MenuBar = new ControlType (MenuBarId, "ControlType.MenuBar");
            MenuBar.localizedControlType = Catalog.GetString("menu bar");
            MenuBar.neverSupportedPatterns = new AutomationPattern [] {};
            MenuBar.requiredProperties = new AutomationProperty [] {};
            MenuBar.requiredPatternSets = new AutomationPattern [] [] {};

            MenuItem = new ControlType (MenuItemId, "ControlType.MenuItem");
            MenuItem.localizedControlType = Catalog.GetString("menu item");
            MenuItem.neverSupportedPatterns = new AutomationPattern [] {};
            MenuItem.requiredProperties = new AutomationProperty [] {};
            MenuItem.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    InvokePatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    ExpandCollapsePatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    TogglePatternIdentifiers.Pattern}
            };

            Menu = new ControlType (MenuId, "ControlType.Menu");
            Menu.localizedControlType = Catalog.GetString("menu");
            Menu.neverSupportedPatterns = new AutomationPattern [] {};
            Menu.requiredProperties = new AutomationProperty [] {};
            Menu.requiredPatternSets = new AutomationPattern [] [] {};

            Pane = new ControlType (PaneId, "ControlType.Pane");
            Pane.localizedControlType = Catalog.GetString("pane");
            Pane.neverSupportedPatterns = new AutomationPattern [] {};
            Pane.requiredProperties = new AutomationProperty [] {};
            Pane.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    TransformPatternIdentifiers.Pattern}
            };

            ProgressBar = new ControlType (ProgressBarId, "ControlType.ProgressBar");
            ProgressBar.localizedControlType = Catalog.GetString("progress bar");
            ProgressBar.neverSupportedPatterns = new AutomationPattern [] {};
            ProgressBar.requiredProperties = new AutomationProperty [] {};
            ProgressBar.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    ValuePatternIdentifiers.Pattern}
            };

            RadioButton = new ControlType (RadioButtonId, "ControlType.RadioButton");
            RadioButton.localizedControlType = Catalog.GetString("radio button");
            RadioButton.neverSupportedPatterns = new AutomationPattern [] {};
            RadioButton.requiredProperties = new AutomationProperty [] {};
            RadioButton.requiredPatternSets = new AutomationPattern [] [] {};

            ScrollBar = new ControlType (ScrollBarId, "ControlType.ScrollBar");
            ScrollBar.localizedControlType = Catalog.GetString("scroll bar");
            ScrollBar.neverSupportedPatterns = new AutomationPattern [] {};
            ScrollBar.requiredProperties = new AutomationProperty [] {};
            ScrollBar.requiredPatternSets = new AutomationPattern [] [] {};

            Separator = new ControlType (SeparatorId, "ControlType.Separator");
            Separator.localizedControlType = Catalog.GetString("separator");
            Separator.neverSupportedPatterns = new AutomationPattern [] {};
            Separator.requiredProperties = new AutomationProperty [] {};
            Separator.requiredPatternSets = new AutomationPattern [] [] {};

            Slider = new ControlType (SliderId, "ControlType.Slider");
            Slider.localizedControlType = Catalog.GetString("slider");
            Slider.neverSupportedPatterns = new AutomationPattern [] {};
            Slider.requiredProperties = new AutomationProperty [] {};
            Slider.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    RangeValuePatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    SelectionPatternIdentifiers.Pattern}
            };

            Spinner = new ControlType (SpinnerId, "ControlType.Spinner");
            Spinner.localizedControlType = Catalog.GetString("spinner");
            Spinner.neverSupportedPatterns = new AutomationPattern [] {};
            Spinner.requiredProperties = new AutomationProperty [] {};
            Spinner.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    RangeValuePatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    SelectionPatternIdentifiers.Pattern}
            };

            SplitButton = new ControlType (SplitButtonId, "ControlType.SplitButton");
            SplitButton.localizedControlType = Catalog.GetString("split button");
            SplitButton.neverSupportedPatterns = new AutomationPattern [] {};
            SplitButton.requiredProperties = new AutomationProperty [] {};
            SplitButton.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    InvokePatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    ExpandCollapsePatternIdentifiers.Pattern}
            };

            StatusBar = new ControlType (StatusBarId, "ControlType.StatusBar");
            StatusBar.localizedControlType = Catalog.GetString("status bar");
            StatusBar.neverSupportedPatterns = new AutomationPattern [] {};
            StatusBar.requiredProperties = new AutomationProperty [] {};
            StatusBar.requiredPatternSets = new AutomationPattern [] [] {};

            TabItem = new ControlType (TabItemId, "ControlType.TabItem");
            TabItem.localizedControlType = Catalog.GetString("tab item");
            TabItem.neverSupportedPatterns = new AutomationPattern [] {};
            TabItem.requiredProperties = new AutomationProperty [] {};
            TabItem.requiredPatternSets = new AutomationPattern [] [] {};

            Table = new ControlType (TableId, "ControlType.Table");
            Table.localizedControlType = Catalog.GetString("table");
            Table.neverSupportedPatterns = new AutomationPattern [] {};
            Table.requiredProperties = new AutomationProperty [] {};
            Table.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    GridPatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    SelectionPatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    TablePatternIdentifiers.Pattern}
            };

            Tab = new ControlType (TabId, "ControlType.Tab");
            Tab.localizedControlType = Catalog.GetString("tab");
            Tab.neverSupportedPatterns = new AutomationPattern [] {};
            Tab.requiredProperties = new AutomationProperty [] {};
            Tab.requiredPatternSets = new AutomationPattern [] [] {};

            Text = new ControlType (TextId, "ControlType.Text");
            Text.localizedControlType = Catalog.GetString("text");
            Text.neverSupportedPatterns = new AutomationPattern [] {};
            Text.requiredProperties = new AutomationProperty [] {};
            Text.requiredPatternSets = new AutomationPattern [] [] {};

            Thumb = new ControlType (ThumbId, "ControlType.Thumb");
            Thumb.localizedControlType = Catalog.GetString("thumb");
            Thumb.neverSupportedPatterns = new AutomationPattern [] {};
            Thumb.requiredProperties = new AutomationProperty [] {};
            Thumb.requiredPatternSets = new AutomationPattern [] [] {};

            TitleBar = new ControlType (TitleBarId, "ControlType.TitleBar");
            TitleBar.localizedControlType = Catalog.GetString("title bar");
            TitleBar.neverSupportedPatterns = new AutomationPattern [] {};
            TitleBar.requiredProperties = new AutomationProperty [] {};
            TitleBar.requiredPatternSets = new AutomationPattern [] [] {};

            ToolBar = new ControlType (ToolBarId, "ControlType.ToolBar");
            ToolBar.localizedControlType = Catalog.GetString("tool bar");
            ToolBar.neverSupportedPatterns = new AutomationPattern [] {};
            ToolBar.requiredProperties = new AutomationProperty [] {};
            ToolBar.requiredPatternSets = new AutomationPattern [] [] {};

            ToolTip = new ControlType (ToolTipId, "ControlType.ToolTip");
            ToolTip.localizedControlType = Catalog.GetString("tool tip");
            ToolTip.neverSupportedPatterns = new AutomationPattern [] {};
            ToolTip.requiredProperties = new AutomationProperty [] {};
            ToolTip.requiredPatternSets = new AutomationPattern [] [] {};

            TreeItem = new ControlType (TreeItemId, "ControlType.TreeItem");
            TreeItem.localizedControlType = Catalog.GetString("tree view item");
            TreeItem.neverSupportedPatterns = new AutomationPattern [] {};
            TreeItem.requiredProperties = new AutomationProperty [] {};
            TreeItem.requiredPatternSets = new AutomationPattern [] [] {};

            Tree = new ControlType (TreeId, "ControlType.Tree");
            Tree.localizedControlType = Catalog.GetString("tree view");
            Tree.neverSupportedPatterns = new AutomationPattern [] {};
            Tree.requiredProperties = new AutomationProperty [] {};
            Tree.requiredPatternSets = new AutomationPattern [] [] {};

            Window = new ControlType (WindowId, "ControlType.Window");
            Window.localizedControlType = Catalog.GetString("window");
            Window.neverSupportedPatterns = new AutomationPattern [] {};
            Window.requiredProperties = new AutomationProperty [] {};
            Window.requiredPatternSets = new AutomationPattern [] [] {
                new AutomationPattern [] {
                    TransformPatternIdentifiers.Pattern},
                new AutomationPattern [] {
                    WindowPatternIdentifiers.Pattern}
            };
        }
        /// <summary>
        /// show properties of an item - use Reflection technology
        /// </summary>
        /// <returns></returns>
        private bool ShowProperties()
        {
            AutomationElement.AutomationElementInformation source = Object.AutomationElement.Current;
            //(Object as TestStack.White.UIItems.WindowItems.Window).
            // get all property methods of Object - use Reflection
            PropertyInfo[] properties = source.GetType().GetProperties();
            bool           ret        = true;

            try
            {
                // currently stop updating the list
                listView.BeginUpdate();

                // if current object is not matched
                if (CurrentInterface == null || CurrentName == null)
                {
                    CandidateName = "";

                    // loop for each property
                    foreach (PropertyInfo prop in properties)
                    {
                        // get property name and value
                        string strName = prop.Name;
                        object objVal  = prop.GetValue(source);

                        // create a corresponding item in the list
                        if (objVal != null)
                        {
                            ListViewItem item   = new ListViewItem(strName);
                            string       strVal = objVal.ToString();
                            if (objVal is System.Windows.Automation.ControlType)
                            {
                                System.Windows.Automation.ControlType c = objVal as System.Windows.Automation.ControlType;
                                strVal = c.ProgrammaticName.Substring(c.ProgrammaticName.IndexOf('.') + 1);
                            }
                            item.SubItems.Add(strVal);
                            listView.Items.Add(item);

                            if (strName.Equals(ABT.Auto.Constants.PropertyNames.AutomationId, StringComparison.CurrentCultureIgnoreCase))
                            {
                                CandidateName = CandidateName + strVal;
                            }
                            else if (strName.Equals(ABT.Auto.Constants.PropertyNames.ControlType, StringComparison.CurrentCultureIgnoreCase))
                            {
                                CandidateName = strVal + CandidateName;
                            }
                        }
                    }
                }
                else if (Object is TestStack.White.UIItems.WindowItems.Window)
                {
                    // loop for each property
                    foreach (PropertyInfo prop in properties)
                    {
                        // get property name and value
                        string strName = prop.Name;
                        object objVal  = prop.GetValue(source);

                        // create a corresponding item in the list
                        if (objVal != null)
                        {
                            ListViewItem item   = new ListViewItem(strName);
                            string       strVal = objVal.ToString();
                            if (objVal is System.Windows.Automation.ControlType)
                            {
                                System.Windows.Automation.ControlType c = objVal as System.Windows.Automation.ControlType;
                                strVal = c.ProgrammaticName.Substring(c.ProgrammaticName.IndexOf('.') + 1);
                            }
                            item.SubItems.Add(strVal);

                            if (Object is TestStack.White.UIItems.WindowItems.Window &&
                                CurrentInterface.Name.Equals(CurrentName, StringComparison.CurrentCultureIgnoreCase) &&
                                CurrentInterface.Properties.ContainsKey(strName.ToLower()))
                            {
                                item.Checked = true;
                                item.Font    = new Font(SystemFonts.DefaultFont, FontStyle.Bold);
                                listView.Items.Insert(0, item);
                            }
                            else // just show the property
                            {
                                listView.Items.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    // loop for each property
                    foreach (PropertyInfo prop in properties)
                    {
                        // get property name and value
                        string strName = prop.Name;
                        object objVal  = prop.GetValue(source);

                        // create a corresponding item in the list
                        if (objVal != null)
                        {
                            ListViewItem item   = new ListViewItem(strName);
                            string       strVal = objVal.ToString();
                            if (objVal is System.Windows.Automation.ControlType)
                            {
                                System.Windows.Automation.ControlType c = objVal as System.Windows.Automation.ControlType;
                                strVal = c.ProgrammaticName.Substring(c.ProgrammaticName.IndexOf('.') + 1);
                            }
                            item.SubItems.Add(strVal);

                            if (CurrentInterface.Controls.ContainsKey(CurrentName) &&
                                CurrentInterface.Controls[CurrentName].ContainsKey(strName.ToLower()))
                            {
                                item.Checked = true;
                                item.Font    = new Font(SystemFonts.DefaultFont, FontStyle.Bold);
                                listView.Items.Insert(0, item);
                            }
                            else // just show the property
                            {
                                listView.Items.Add(item);
                            }
                        }
                    }
                }
            }
            catch (InvalidCastException)
            {
                // some error occured, we cannot show the properties, so the Object is considered as invalid
                ret = false;
            }
            finally
            {
                // resume updating the list
                listView.EndUpdate();
            }

            return(ret);
        }
예제 #36
0
        internal static AutomationIdentifier Register(UiaCoreTypesApi.AutomationIdType type, Guid guid, string programmaticName)
        {
            int num = UiaCoreTypesApi.UiaLookupId(type, ref guid);

            if (num == 0)
            {
                if ((!AutomationIdentifier.IsWin7OnlyPatternGuid(guid) && Environment.OSVersion.Version.Major <= 6) || Environment.OSVersion.Version.Major >= 7)
                {
                    int num2 = 1;
                    while (num == 0 && num2 < 1000)
                    {
                        Thread.Sleep(num2);
                        num   = UiaCoreTypesApi.UiaLookupId(type, ref guid);
                        num2 *= 2;
                    }
                }
                if (num == 0)
                {
                    return(null);
                }
            }
            Hashtable            idTable = AutomationIdentifier._idTable;
            AutomationIdentifier result;

            lock (idTable)
            {
                AutomationIdentifier automationIdentifier = (AutomationIdentifier)AutomationIdentifier._idTable[guid];
                if (automationIdentifier != null)
                {
                    result = automationIdentifier;
                }
                else
                {
                    switch (type)
                    {
                    case UiaCoreTypesApi.AutomationIdType.Property:
                        automationIdentifier = new AutomationProperty(num, guid, programmaticName);
                        break;

                    case UiaCoreTypesApi.AutomationIdType.Pattern:
                        automationIdentifier = new AutomationPattern(num, guid, programmaticName);
                        break;

                    case UiaCoreTypesApi.AutomationIdType.Event:
                        automationIdentifier = new AutomationEvent(num, guid, programmaticName);
                        break;

                    case UiaCoreTypesApi.AutomationIdType.ControlType:
                        automationIdentifier = new ControlType(num, guid, programmaticName);
                        break;

                    case UiaCoreTypesApi.AutomationIdType.TextAttribute:
                        automationIdentifier = new AutomationTextAttribute(num, guid, programmaticName);
                        break;

                    default:
                        throw new InvalidOperationException("Invalid type specified for AutomationIdentifier");
                    }
                    AutomationIdentifier._idTable[num] = automationIdentifier;
                    result = automationIdentifier;
                }
            }
            return(result);
        }