Esempio n. 1
0
        public async Task CheckboxWithoutLabelShouldNotHaveChildren()
        {
            await Page.SetContentAsync(@"
            <div role='checkbox' aria-checked='true'>
                this is the inner content
                <img alt='yo' src='fakeimg.png'>
            </div>");

            SerializedAXNode node;

            if (TestConstants.IsFirefox)
            {
                node = new SerializedAXNode
                {
                    Role    = "checkbox",
                    Name    = "this is the inner content yo",
                    Checked = CheckedState.Checked
                };
            }
            else
            {
                node = new SerializedAXNode
                {
                    Role    = "checkbox",
                    Name    = "this is the inner content yo",
                    Checked = CheckedState.Checked
                };
            }

            Assert.Equal(node, (await Page.Accessibility.SnapshotAsync()).Children[0]);
        }
 public SerializedAXNode Serialize()
 {
     FirefoxRoleToARIARole.TryGetValue(_role, out string nodeRole);
     var node = new SerializedAXNode
     {
         Role            = nodeRole ?? _role,
         Name            = _name ?? string.Empty,
         Value           = _payload.Value,
         Description     = _payload.Description,
         RoleDescription = _payload.Roledescription,
         ValueText       = _payload.Valuetext,
         KeyShortcuts    = _payload.Keyshortcuts,
         Disabled        = _payload.Disabled ?? false,
         Expanded        = _payload.Expanded ?? false,
         Focused         = _role != "document" && _payload.Focused == true,
         Modal           = _payload.Modal ?? false,
         Multiline       = _payload.Multiline ?? false,
         Multiselectable = _payload.Multiselectable ?? false,
         Readonly        = _payload.Readonly ?? false,
         Required        = _payload.Required ?? false,
         Selected        = _payload.Selected ?? false,
         Checked         = GetChecked(_payload.Checked),
         Pressed         = GetPressed(_payload.Pressed),
         Level           = _payload.Level.HasValue ? (int)_payload.Level : 0,
         AutoComplete    = GetTokenProperty(_payload.Autocomplete),
         HasPopup        = GetTokenProperty(_payload.Haspopup == true ? "true" : null),
         Invalid         = GetTokenProperty(_payload.Invalid == true ? "true" : null),
         Orientation     = GetTokenProperty(_payload.Orientation),
     };
        public async Task RichTextEditableFieldsShouldHaveChildren()
        {
            await Page.SetContentAsync(@"
            <div contenteditable='true'>
                Edit this image: <img src='fakeimage.png' alt='my fake image'>
            </div>");

            SerializedAXNode node;

            if (TestConstants.IsFirefox)
            {
                node = new SerializedAXNode
                {
                    Role     = "section",
                    Name     = "",
                    Children = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role = "text leaf",
                            Name = "Edit this image: "
                        },
                        new SerializedAXNode
                        {
                            Role = "text",
                            Name = "my fake image"
                        }
                    }
                };
            }
            else
            {
                node = new SerializedAXNode
                {
                    Role        = "generic",
                    Name        = "",
                    ValueString = "Edit this image: ",
                    Children    = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role = "text",
                            Name = "Edit this image:"
                        },
                        new SerializedAXNode
                        {
                            Role = "img",
                            Name = "my fake image"
                        }
                    }
                };
            }

            var snapshot = await Page.Accessibility.SnapshotAsync();

            Assert.Equal(node, snapshot.Children[0]);
        }
Esempio n. 4
0
        public SerializedAXNode Serialize()
        {
            var properties = new Dictionary <string, JsonElement?>();

            foreach (var property in Payload.Properties)
            {
                properties[property.Name.ToString().ToLower()] = (JsonElement?)property?.Value?.Value;
            }

            if (Payload.Name != null)
            {
                properties["name"] = (JsonElement)Payload.Name.Value;
            }

            if (Payload.Value != null)
            {
                properties["value"] = (JsonElement)Payload.Value.Value;
            }

            if (Payload.Description != null)
            {
                properties["description"] = (JsonElement)Payload.Description.Value;
            }

            var node = new SerializedAXNode
            {
                Role            = _role,
                Name            = properties.GetValueOrDefault("name")?.ToString(),
                Value           = properties.GetValueOrDefault("value")?.ToString(),
                Description     = properties.GetValueOrDefault("description")?.ToString(),
                KeyShortcuts    = properties.GetValueOrDefault("keyshortcuts")?.ToString(),
                RoleDescription = properties.GetValueOrDefault("roledescription")?.ToString(),
                ValueText       = properties.GetValueOrDefault("valuetext")?.ToString(),
                Disabled        = properties.GetValueOrDefault("disabled")?.ToObject <bool>() ?? false,
                Expanded        = properties.GetValueOrDefault("expanded")?.ToObject <bool>() ?? false,
                Focused         = properties.GetValueOrDefault("focused")?.ToObject <bool>() == true && _role != "WebArea",
                Modal           = properties.GetValueOrDefault("modal")?.ToObject <bool>() ?? false,
                Multiline       = properties.GetValueOrDefault("multiline")?.ToObject <bool>() ?? false,
                Multiselectable = properties.GetValueOrDefault("multiselectable")?.ToObject <bool>() ?? false,
                Readonly        = properties.GetValueOrDefault("readonly")?.ToObject <bool>() ?? false,
                Required        = properties.GetValueOrDefault("required")?.ToObject <bool>() ?? false,
                Selected        = properties.GetValueOrDefault("selected")?.ToObject <bool>() ?? false,
                Checked         = GetCheckedState(properties.GetValueOrDefault("checked")?.ToString()),
                Pressed         = GetCheckedState(properties.GetValueOrDefault("pressed")?.ToString()),
                Level           = properties.GetValueOrDefault("level")?.ToObject <int>() ?? 0,
                ValueMax        = properties.GetValueOrDefault("valuemax")?.ToObject <int>() ?? 0,
                ValueMin        = properties.GetValueOrDefault("valuemin")?.ToObject <int>() ?? 0,
                AutoComplete    = GetIfNotFalse(properties.GetValueOrDefault("autocomplete")?.ToString()),
                HasPopup        = GetIfNotFalse(properties.GetValueOrDefault("haspopup")?.ToString()),
                Invalid         = GetIfNotFalse(properties.GetValueOrDefault("invalid")?.ToString()),
                Orientation     = GetIfNotFalse(properties.GetValueOrDefault("orientation")?.ToString()),
            };

            return(node);
        }
Esempio n. 5
0
        public async Task RichTextEditableFieldsWithRoleShouldHaveChildren()
        {
            await Page.SetContentAsync(@"
            <div contenteditable='true' role='textbox'>
                Edit this image: <img src='fakeimage.png' alt='my fake image'>
            </div>");

            SerializedAXNode node;

            if (TestConstants.IsFirefox)
            {
                node = new SerializedAXNode
                {
                    Role     = "textbox",
                    Name     = "",
                    Value    = "Edit this image: my fake image",
                    Children = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role = "text",
                            Name = "my fake image"
                        }
                    }
                };
            }
            else
            {
                node = new SerializedAXNode
                {
                    Role     = "textbox",
                    Name     = "",
                    Value    = "Edit this image: ",
                    Children = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role = "text",
                            Name = "Edit this image:"
                        },
                        new SerializedAXNode
                        {
                            Role = "img",
                            Name = "my fake image"
                        }
                    }
                };
            }

            Assert.Equal(node, (await Page.Accessibility.SnapshotAsync()).Children[0]);
        }
        private SerializedAXNode FindFocusedNode(SerializedAXNode serializedAXNode)
        {
            if (serializedAXNode.Focused)
            {
                return(serializedAXNode);
            }
            foreach (var item in serializedAXNode.Children)
            {
                var focusedChild = FindFocusedNode(item);
                if (focusedChild != null)
                {
                    return(focusedChild);
                }
            }

            return(null);
        }
Esempio n. 7
0
        public async Task ShouldWorkOnAMenu()
        {
            await Page.SetContentAsync(@"
            <div role=""menu"" title=""My Menu"">
              <div role=""menuitem"">First Item</div>
              <div role=""menuitem"">Second Item</div>
              <div role=""menuitem"">Third Item</div>
            </div>
            ");

            var menu = await Page.QuerySelectorAsync("div[role=\"menu\"]");

            var nodeToCheck = new SerializedAXNode
            {
                Role     = "menu",
                Name     = "My Menu",
                Children = new SerializedAXNode[]
                {
                    new SerializedAXNode
                    {
                        Role = "menuitem",
                        Name = "First Item"
                    },
                    new SerializedAXNode
                    {
                        Role = "menuitem",
                        Name = "Second Item"
                    },
                    new SerializedAXNode
                    {
                        Role = "menuitem",
                        Name = "Third Item"
                    }
                },
                Orientation = TestConstants.IsWebKit ? "vertical" : null
            };

            CompareLogic compareLogic = new CompareLogic();
            var          result       = compareLogic.Compare(nodeToCheck, await Page.Accessibility.SnapshotAsync(root: menu));

            Assert.True(result.AreEqual, result.DifferencesString);
        }
Esempio n. 8
0
        public async Task ShouldWorkAMenu()
        {
            await Page.SetContentAsync(@"
            <div role=""menu"" title=""My Menu"" >
              <div role=""menuitem"">First Item</div>
              <div role=""menuitem"">Second Item</div>
              <div role=""menuitem"">Third Item</div>
            </div>
            ");

            var menu = await Page.QuerySelectorAsync("div[role=\"menu\"]");

            var snapshot = await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = menu });

            var nodeToCheck = new SerializedAXNode
            {
                Role        = "menu",
                Name        = "My Menu",
                Orientation = "vertical",
                Children    = new[]
                {
                    new SerializedAXNode
                    {
                        Role = "menuitem",
                        Name = "First Item"
                    },
                    new SerializedAXNode
                    {
                        Role = "menuitem",
                        Name = "Second Item"
                    },
                    new SerializedAXNode
                    {
                        Role = "menuitem",
                        Name = "Third Item"
                    }
                }
            };

            Assert.Equal(nodeToCheck, snapshot);
        }
Esempio n. 9
0
        public async Task NonEditableTextboxWithRoleAndTabIndexAndLabelShouldNotHaveChildren()
        {
            await Page.SetContentAsync(@"
            <div role='textbox' tabIndex=0 aria-checked='true' aria-label='my favorite textbox'>
                this is the inner content
                <img alt='yo' src='fakeimg.png'>
            </div>");

            SerializedAXNode node = null;

            if (TestConstants.IsFirefox)
            {
                node = new SerializedAXNode
                {
                    Role        = "textbox",
                    Name        = "my favorite textbox",
                    ValueString = "this is the inner content yo"
                };
            }
            else if (TestConstants.IsChromium)
            {
                node = new SerializedAXNode
                {
                    Role        = "textbox",
                    Name        = "my favorite textbox",
                    ValueString = "this is the inner content "
                };
            }
            else
            {
                node = new SerializedAXNode
                {
                    Role        = "textbox",
                    Name        = "my favorite textbox",
                    ValueString = "this is the inner content  "
                };
            }
            Assert.Equal(node, (await Page.Accessibility.SnapshotAsync()).Children[0]);
        }
Esempio n. 10
0
        public async Task ShouldWork()
        {
            await Page.SetContentAsync(@"
            <head>
                <title>Accessibility Test</title>
            </head>
            <body>
                <h1>Inputs</h1>
                <input placeholder='Empty input' autofocus />
                <input placeholder='readonly input' readonly />
                <input placeholder='disabled input' disabled />
                <input aria-label='Input with whitespace' value='  ' />
                <input value='value only' />
                <input aria-placeholder='placeholder' value='and a value' />
                <div aria-hidden='true' id='desc'>This is a description!</div>
                <input aria-placeholder='placeholder' value='and a value' aria-describedby='desc' />
            </body>");

            SerializedAXNode nodeToCheck;

            if (TestConstants.IsFirefox)
            {
                nodeToCheck = new SerializedAXNode
                {
                    Role     = "document",
                    Name     = "Accessibility Test",
                    Children = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role  = "heading",
                            Name  = "Inputs",
                            Level = 1
                        },
                        new SerializedAXNode {
                            Role    = "textbox",
                            Name    = "Empty input",
                            Focused = true
                        },
                        new SerializedAXNode {
                            Role     = "textbox",
                            Name     = "readonly input",
                            Readonly = true
                        },
                        new SerializedAXNode {
                            Role     = "textbox",
                            Name     = "disabled input",
                            Disabled = true
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "Input with whitespace",
                            ValueString = "  "
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = string.Empty,
                            ValueString = "value only"
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = string.Empty,
                            ValueString = "and a value"
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = string.Empty,
                            ValueString = "and a value",
                            Description = "This is a description!"
                        }
                    }
                };
            }
            else if (TestConstants.IsChromium)
            {
                nodeToCheck = new SerializedAXNode
                {
                    Role     = "WebArea",
                    Name     = "Accessibility Test",
                    Children = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role  = "heading",
                            Name  = "Inputs",
                            Level = 1
                        },
                        new SerializedAXNode {
                            Role    = "textbox",
                            Name    = "Empty input",
                            Focused = true
                        },
                        new SerializedAXNode {
                            Role     = "textbox",
                            Name     = "readonly input",
                            Readonly = true
                        },
                        new SerializedAXNode {
                            Role     = "textbox",
                            Name     = "disabled input",
                            Disabled = true
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "Input with whitespace",
                            ValueString = "  "
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "",
                            ValueString = "value only"
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "placeholder",
                            ValueString = "and a value"
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "placeholder",
                            ValueString = "and a value",
                            Description = "This is a description!"
                        }
                    }
                };
            }
            else
            {
                nodeToCheck = new SerializedAXNode
                {
                    Role     = "WebArea",
                    Name     = "Accessibility Test",
                    Children = new SerializedAXNode[]
                    {
                        new SerializedAXNode
                        {
                            Role  = "heading",
                            Name  = "Inputs",
                            Level = 1
                        },
                        new SerializedAXNode {
                            Role    = "textbox",
                            Name    = "Empty input",
                            Focused = true
                        },
                        new SerializedAXNode {
                            Role     = "textbox",
                            Name     = "readonly input",
                            Readonly = true
                        },
                        new SerializedAXNode {
                            Role     = "textbox",
                            Name     = "disabled input",
                            Disabled = true
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "Input with whitespace",
                            ValueString = "  "
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "",
                            ValueString = "value only"
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "placeholder",
                            ValueString = "and a value"
                        },
                        new SerializedAXNode {
                            Role        = "textbox",
                            Name        = "This is a description!",
                            ValueString = "and a value"
                        }
                    }
                };
            }

            var snapshot = await Page.Accessibility.SnapshotAsync();

            CompareLogic compareLogic = new CompareLogic();
            var          result       = compareLogic.Compare(nodeToCheck, snapshot);

            Assert.True(result.AreEqual, result.DifferencesString);
        }
        public async Task ShouldWork()
        {
            await Page.SetContentAsync(@"
            <head>
                <title>Accessibility Test</title>
            </head>
            <body>
                <div>Hello World</div>
                <h1>Inputs</h1>
                <input placeholder='Empty input' autofocus />
                <input placeholder='readonly input' readonly />
                <input placeholder='disabled input' disabled />
                <input aria-label='Input with whitespace' value='  ' />
                <input value='value only' />
                <input aria-placeholder='placeholder' value='and a value' />
                <div aria-hidden='true' id='desc'>This is a description!</div>
                <input aria-placeholder='placeholder' value='and a value' aria-describedby='desc' />
                <select>
                    <option>First Option</option>
                    <option>Second Option</option>
                </select>
            </body>");

            var nodeToCheck = new SerializedAXNode
            {
                Role     = "WebArea",
                Name     = "Accessibility Test",
                Children = new SerializedAXNode[]
                {
                    new SerializedAXNode
                    {
                        Role = "text",
                        Name = "Hello World"
                    },
                    new SerializedAXNode
                    {
                        Role  = "heading",
                        Name  = "Inputs",
                        Level = 1
                    },
                    new SerializedAXNode {
                        Role    = "textbox",
                        Name    = "Empty input",
                        Focused = true
                    },
                    new SerializedAXNode {
                        Role     = "textbox",
                        Name     = "readonly input",
                        Readonly = true
                    },
                    new SerializedAXNode {
                        Role     = "textbox",
                        Name     = "disabled input",
                        Disabled = true
                    },
                    new SerializedAXNode {
                        Role  = "textbox",
                        Name  = "Input with whitespace",
                        Value = "  "
                    },
                    new SerializedAXNode {
                        Role  = "textbox",
                        Name  = "",
                        Value = "value only"
                    },
                    new SerializedAXNode {
                        Role  = "textbox",
                        Name  = "placeholder",
                        Value = "and a value"
                    },
                    new SerializedAXNode {
                        Role        = "textbox",
                        Name        = "placeholder",
                        Value       = "and a value",
                        Description = "This is a description!"
                    },
                    new SerializedAXNode {
                        Role     = "combobox",
                        Name     = "",
                        Value    = "First Option",
                        Children = new SerializedAXNode[] {
                            new SerializedAXNode
                            {
                                Role     = "menuitem",
                                Name     = "First Option",
                                Selected = true
                            },
                            new SerializedAXNode
                            {
                                Role = "menuitem",
                                Name = "Second Option"
                            }
                        }
                    }
                }
            };
            await Page.FocusAsync("[placeholder='Empty input']");

            var snapshot = await Page.Accessibility.SnapshotAsync();

            Assert.Equal(nodeToCheck, snapshot);
        }