Exemplo n.º 1
0
        private static Condition CreateAllowSameNameAndControlTypeCondition()
        {
            /* the following are generally found one per window/app
             * And therefore don't benefit from name-based distinction.
             * And for many, it's easy to imagine it being difficult to come up with a meaningful name beyond the control type.
             * What else do you call a StatusBar for example?
             * Custom elements are handled separately because there may be times
             * when a name is "page 1" for example and the type is "page"
             * which we currently believe is acceptable because screen readers will read the name then the type
             * and "1 page" would sound awkward.
             * Names that are particularly long are viewed as acceptable because they are
             * more likely to be informative and not to cause double speaking by screen readers.
             * */

            var types = AppBar | Custom | Header | MenuBar | SemanticZoom | StatusBar | TitleBar | Text;

            /*
             * For edit controls in Edge prior to Anaheim, the name property for password and e-mail
             * fields will contain "password" and "email" in the LocalizedControlType property.
             * Since this cannot be addressed by users, and because that version of Edge is legacy, such edit fields are allowed.
             */

            var edgeEdits = Edit
                            & Edge
                            & (LocalizedControlType.IsNoCase("password")
                               | LocalizedControlType.IsNoCase("email"));

            return(types | Name.Length > 50 | edgeEdits);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a SearchCondition object that is used to locate elements.
        /// </summary>
        /// <param name="By">Enumeration for the Property by which to locate the element.</param>
        /// <param name="ByValue">The value of the corresponding Element property.</param>
        /// <param name="Type">Enumeration for specifying the Control Type of the Element.</param>
        public SearchCondition(By By, string ByValue, LocalizedControlType Type)
        {
            this.By          = By;
            this.ByValue     = ByValue;
            this.ControlType = Type;

            this.UIAutomationCondition = CreateSearchCondition(this.By, this.ByValue, this.ControlType);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Internal method for creating the IUIAutomationCondition used to locate elements.
        /// </summary>
        /// <param name="By"></param>
        /// <param name="Value"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        private IUIAutomationCondition CreateSearchCondition(By By, string Value, LocalizedControlType Type)
        {
            IUIAutomationAndCondition cond = (IUIAutomationAndCondition) new CUIAutomationClass().CreateAndConditionFromArray(new IUIAutomationCondition[]
            {
                new CUIAutomationClass().CreatePropertyCondition(By.GetId(), Value),
                new CUIAutomationClass().CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, Type.GetControlTypeValue())
            });

            return(cond as IUIAutomationCondition);
        }
        public static string GetControlTypeValue(this LocalizedControlType type)
        {
            string value = "";

            switch (type)
            {
            case LocalizedControlType.Button: value = "button"; break;

            case LocalizedControlType.CheckBox: value = "check box"; break;

            case LocalizedControlType.ComboBox: value = "combo box"; break;

            case LocalizedControlType.Custom: value = "custom"; break;

            case LocalizedControlType.Dataitem: value = "dataitem"; break;

            case LocalizedControlType.Dialog: value = "dialog"; break;

            case LocalizedControlType.Edit: value = "edit"; break;

            case LocalizedControlType.ListBox: value = "list"; break;

            case LocalizedControlType.ListItem: value = "list item"; break;

            case LocalizedControlType.MenuItem: value = "menu item"; break;

            case LocalizedControlType.Pane: value = "pane"; break;

            case LocalizedControlType.RadioButton: value = "radio button"; break;

            case LocalizedControlType.SplitButton: value = "split button"; break;

            case LocalizedControlType.StatusBar: value = "status bar"; break;

            case LocalizedControlType.Tab: value = "tab"; break;

            case LocalizedControlType.TabItem: value = "tab item"; break;

            case LocalizedControlType.Text: value = "text"; break;

            case LocalizedControlType.Toolbar: value = "tool bar"; break;

            case LocalizedControlType.Tree: value = "tree"; break;

            case LocalizedControlType.TreeItem: value = "tree item"; break;

            case LocalizedControlType.TreeView: value = "tree view"; break;

            case LocalizedControlType.Window: value = "window"; break;

            default: throw new Exception("The given enum is not present in the switch!!!");
            }
            return(value);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get all elements from the current element that match the specified control type.
        /// </summary>
        /// <param name="Scope"></param>
        /// <param name="ControlType"></param>
        /// <returns></returns>
        public ControlElement[] GetControlsByControlType(TreeScope Scope, LocalizedControlType ControlType)
        {
            IUIAutomationElementArray elementsToFind = null;
            IUIAutomationCondition    cond           = new CUIAutomationClass().CreatePropertyCondition(By.ControlType.GetId(), ControlType.GetControlTypeValue());

            elementsToFind = this.IUIElement.FindAll(Scope, cond);
            int size = elementsToFind.Length;

            ControlElement[] arr = new ControlElement[size];
            for (int i = 0; i < size; i++)
            {
                arr[i] = new ControlElement(elementsToFind.GetElement(i));
            }
            return(arr);
        }
        public override bool PassesTest(IA11yElement e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.Parent == null)
            {
                throw new ArgumentException(ErrorMessages.ElementParentNull, nameof(e));
            }

            var siblings = SiblingCount(EligibleChild
                                        & Name.Is(e.Name)
                                        & LocalizedControlType.Is(e.LocalizedControlType));
            var count = siblings.GetValue(e);

            if (count < 1)
            {
                throw new AxeWindowsException(string.Format(CultureInfo.InvariantCulture, ErrorMessages.NoElementFound, this.Info.ID));
            }

            return(count == 1);
        }
Exemplo n.º 7
0
        public override EvaluationCode Evaluate(IA11yElement e)
        {
            if (e == null)
            {
                throw new ArgumentException(nameof(e));
            }
            if (e.Parent == null)
            {
                throw new ArgumentNullException(nameof(e.Parent));
            }

            var siblings = SiblingCount(EligibleChild
                                        & Name.Is(e.Name)
                                        & LocalizedControlType.Is(e.LocalizedControlType));
            var count = siblings.GetValue(e);

            if (count < 1)
            {
                return(EvaluationCode.RuleExecutionError);
            }

            return(count == 1 ? EvaluationCode.Pass : EvaluationCode.Note);
        }
Exemplo n.º 8
0
        public override bool PassesTest(IA11yElement e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.Parent == null)
            {
                throw new ArgumentException(ErrorMessages.ElementParentNull, nameof(e));
            }

            var siblings = SiblingCount(new ControlTypeCondition(e.ControlTypeId)
                                        & (e.IsKeyboardFocusable ? IsKeyboardFocusable : IsNotKeyboardFocusable)
                                        & Name.Is(e.Name)
                                        & LocalizedControlType.Is(e.LocalizedControlType));
            var count = siblings.GetValue(e);

            if (count < 1)
            {
                throw new Exception(String.Format(CultureInfo.InvariantCulture, ErrorMessages.NoElementFound, this.Info.ID));
            }

            return(count == 1);
        }
        public override EvaluationCode Evaluate(IA11yElement e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.Parent == null)
            {
                throw new ArgumentException(ErrorMessages.ElementParentNull, nameof(e));
            }

            var siblings = SiblingCount(new ControlTypeCondition(e.ControlTypeId)
                                        & (e.IsKeyboardFocusable ? IsKeyboardFocusable : IsNotKeyboardFocusable)
                                        & Name.Is(e.Name)
                                        & LocalizedControlType.Is(e.LocalizedControlType));
            var count = siblings.GetValue(e);

            if (count < 1)
            {
                return(EvaluationCode.RuleExecutionError);
            }

            return(count == 1 ? EvaluationCode.Pass : EvaluationCode.Warning);
        }