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>");

            AccessibilitySnapshotResult node;

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

            Assert.Equal(node, (await Page.Accessibility.SnapshotAsync()).Children.First());
        }
        public async Task RichTextEditableFieldsShouldHaveChildren()
        {
            await Page.SetContentAsync(@"
            <div contenteditable='true'>
                Edit this image: <img src='fakeimage.png' alt='my fake image'>
            </div>");

            AccessibilitySnapshotResult node;

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

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

            Assert.Equal(node, snapshot.Children.First());
        }
        public async Task RichTextEditableFieldsWithRoleShouldHaveChildren()
        {
            await Page.SetContentAsync(@"
            <div contenteditable='true' role='textbox'>
                Edit this image: <img src='fakeimage.png' alt='my fake image'>
            </div>");

            AccessibilitySnapshotResult node;

            if (TestConstants.IsFirefox)
            {
                node = new AccessibilitySnapshotResult
                {
                    Role     = "textbox",
                    Name     = "",
                    Value    = "Edit this image: my fake image",
                    Children = new List <AccessibilitySnapshotResult>
                    {
                        new AccessibilitySnapshotResult
                        {
                            Role = "text",
                            Name = "my fake image"
                        }
                    }
                };
            }
            else
            {
                node = new AccessibilitySnapshotResult
                {
                    Role      = "textbox",
                    Name      = "",
                    Value     = "Edit this image: ",
                    Multiline = TestConstants.IsChromium && Browser.GetMajorVersion() >= 92 ? true : null,
                    Children  = new List <AccessibilitySnapshotResult>
                    {
                        new AccessibilitySnapshotResult
                        {
                            Role = "text",
                            Name = "Edit this image:"
                        },
                        new AccessibilitySnapshotResult
                        {
                            Role = "img",
                            Name = "my fake image"
                        }
                    }
                };
            }

            var compareLogic = new CompareLogic();
            var result       = compareLogic.Compare(node, (await Page.Accessibility.SnapshotAsync()).Children.First());

            Assert.True(result.AreEqual, result.DifferencesString);
        }
        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 AccessibilitySnapshotResult
            {
                Role     = "menu",
                Name     = "My Menu",
                Children = new AccessibilitySnapshotResult[]
                {
                    new AccessibilitySnapshotResult
                    {
                        Role = "menuitem",
                        Name = "First Item"
                    },
                    new AccessibilitySnapshotResult
                    {
                        Role = "menuitem",
                        Name = "Second Item"
                    },
                    new AccessibilitySnapshotResult
                    {
                        Role = "menuitem",
                        Name = "Third Item"
                    }
                }.ToList(),
                Orientation = TestConstants.IsWebKit ? "vertical" : null
            };

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

            Assert.True(result.AreEqual, result.DifferencesString);
        }
        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>");

            AccessibilitySnapshotResult node = null;

            if (TestConstants.IsFirefox)
            {
                node = new AccessibilitySnapshotResult
                {
                    Role  = "textbox",
                    Name  = "my favorite textbox",
                    Value = "this is the inner content yo"
                };
            }
            else if (TestConstants.IsChromium)
            {
                node = new AccessibilitySnapshotResult
                {
                    Role  = "textbox",
                    Name  = "my favorite textbox",
                    Value = "this is the inner content "
                };
            }
            else
            {
                node = new AccessibilitySnapshotResult
                {
                    Role  = "textbox",
                    Name  = "my favorite textbox",
                    Value = "this is the inner content  "
                };
            }
            Assert.Equal(node, (await Page.Accessibility.SnapshotAsync()).Children.First());
        }
        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>");

            AccessibilitySnapshotResult nodeToCheck;

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

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

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

            Assert.True(result.AreEqual, result.DifferencesString);
        }