Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public async Task PlainTextFieldWithTabindexAndWithoutRoleShouldNotHaveContent()
Assert.That(node.Name, Is.Empty);
}

[PlaywrightTest("page-accessibility.spec.ts", "contenteditable", "non editable textbox with role and tabIndex and label should not have children")]
[SkipBrowserAndPlatformFact(skipWebkit: true, skipFirefox: true)]
[PlaywrightTest("page-accessibility.spec.ts", "non editable textbox with role and tabIndex and label should not have children")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task NonEditableTextboxWithRoleAndTabIndexAndLabelShouldNotHaveChildren()
{
await Page.SetContentAsync(@"
Expand Down Expand Up @@ -86,8 +86,8 @@ this is the inner content
Assert.That((await Page.Accessibility.SnapshotAsync()).Children.First(), Is.EqualTo(node));
}

[PlaywrightTest("page-accessibility.spec.ts", "contenteditable", "checkbox with and tabIndex and label should not have children")]
[SkipBrowserAndPlatformFact(skipWebkit: true, skipFirefox: true)]
[PlaywrightTest("page-accessibility.spec.ts", "checkbox with and tabIndex and label should not have children")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task CheckboxWithAndTabIndexAndLabelShouldNotHaveChildren()
{
await Page.SetContentAsync(@"
Expand All @@ -103,8 +103,8 @@ this is the inner content
}));
}

[PlaywrightTest("page-accessibility.spec.ts", "contenteditable", "checkbox without label should not have children")]
[SkipBrowserAndPlatformFact(skipWebkit: true, skipFirefox: true)]
[PlaywrightTest("page-accessibility.spec.ts", "checkbox without label should not have children")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task CheckboxWithoutLabelShouldNotHaveChildren()
{
await Page.SetContentAsync(@"
Expand Down
70 changes: 56 additions & 14 deletions src/PlaywrightSharp.Tests/PageAccessibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ await Page.SetContentAsync(@"
<input aria-placeholder='placeholder' value='and a value' aria-describedby='desc' />
</body>");

// autofocus happens after a delay in chrome these days
await Page.WaitForFunctionAsync("() => document.activeElement.hasAttribute('autofocus')");

AccessibilitySnapshotResult nodeToCheck;

if (TestConstants.IsFirefox)
Expand Down Expand Up @@ -183,7 +186,7 @@ await Page.SetContentAsync(@"
},
new AccessibilitySnapshotResult {
Role = "textbox",
Name = "This is a description!",
Name = TestConstants.IsMacOSX ? "placeholder" : "This is a description!",
Value = "and a value" }
}.ToList()
};
Expand Down Expand Up @@ -213,7 +216,7 @@ public async Task ShouldWorkWithRegularRext()
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task RoleDescription()
{
await Page.SetContentAsync("<div tabIndex=-1 aria-roledescription=\"foo\">Hi</div>");
await Page.SetContentAsync("<p tabIndex=-1 aria-roledescription=\"foo\">Hi</p>");
var snapshot = (await Page.Accessibility.SnapshotAsync());
Assert.That(snapshot.Children.First().Roledescription, Is.EqualTo("foo"));
}
Expand All @@ -231,9 +234,10 @@ public async Task Orientation()
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task Autocomplete()
{
await Page.SetContentAsync("<div role=\"textbox\" aria-autocomplete=\"list\">hi</div>");
await Page.SetContentAsync("<div role=\"textbox\" aria-autocomplete=\"list\" aria-haspopup=\"menu\">hi</div>");
var snapshot = (await Page.Accessibility.SnapshotAsync());
Assert.That(snapshot.Children.First().Autocomplete, Is.EqualTo("list"));
Assert.That(snapshot.Children.First().Haspopup, Is.EqualTo("menu"));
}

[PlaywrightTest("page-accessibility.spec.ts", "multiselectable")]
Expand All @@ -254,9 +258,9 @@ public async Task KeyShortcuts()
Assert.That(snapshot.Children.First().Keyshortcuts, Is.EqualTo("foo"));
}

[PlaywrightTest("page-accessibility.spec.ts", "filtering children of leaf nodes")]
[PlaywrightTest("page-accessibility.spec.ts", "should not report text nodes inside controls")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task FilteringChildrenOfLeafNodes()
public async Task ShouldNotReportTextNodesInsideControls()
{
await Page.SetContentAsync(@"
<div role=""tablist"">
Expand Down Expand Up @@ -330,11 +334,11 @@ await Page.SetContentAsync(@"
new AccessibilitySnapshotResult
{
Role = "text",
Name = "Edit this image:"
Name = "Edit this image: "
},
new AccessibilitySnapshotResult
{
Role = "img",
Role = "image",
Name = "my fake image"
}
}
Expand Down Expand Up @@ -379,18 +383,14 @@ await Page.SetContentAsync(@"
{
Role = "textbox",
Name = "",
Multiline = true,
Value = "Edit this image: ",
Children = new AccessibilitySnapshotResult[]
{
new AccessibilitySnapshotResult
{
Role = "text",
Name = "Edit this image:"
},
new AccessibilitySnapshotResult
{
Role = "img",
Name = "my fake image"
Name = "Edit this image: "
}
}
};
Expand Down Expand Up @@ -463,7 +463,7 @@ await Page.SetContentAsync(@"
Name = "Third Item"
}
}.ToList(),
Orientation = TestConstants.IsWebKit ? "vertical" : null
Orientation = (TestConstants.IsWebKit || TestConstants.IsChromium) ? "vertical" : null
};

CompareLogic compareLogic = new CompareLogic();
Expand Down Expand Up @@ -519,5 +519,47 @@ await Page.SetContentAsync(@"
return null;
};
}

[PlaywrightTest("page-accessibility.spec.ts", "should work when there is a title")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldWorkWhenThereIsATitle()
{
await Page.SetContentAsync(@"
<title>This is the title</title>
<div>This is the content</div>
");
var snapshot = (await Page.Accessibility.SnapshotAsync());
Assert.That(snapshot.Name, Is.EqualTo("This is the title"));
Assert.That(snapshot.Children.First().Name, Is.EqualTo("This is the content"));
}

[PlaywrightTest("page-accessibility.spec.ts", "should work with aria-invalid accessibility tree")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldWorkWithAriaInvalidAccessibilityTree()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.SetContentAsync("<a href=\"/hi\" aria-invalid=\"true\">WHO WE ARE</a>");

var snapshot = (await Page.Accessibility.SnapshotAsync());
var expected = new AccessibilitySnapshotResult
{
Role = TestConstants.IsFirefox ? "document" : "WebArea",
Name = "",
Children = new AccessibilitySnapshotResult[]
{
new AccessibilitySnapshotResult
{
Role = "link",
Name = "WHO WE ARE",
Invalid = "true",
Value = TestConstants.IsFirefox ? TestConstants.ServerUrl + "/hi" : null,
}
}
};

CompareLogic compareLogic = new CompareLogic();
var result = compareLogic.Compare(expected, snapshot);
Assert.That(result.AreEqual, Is.True, result.DifferencesString);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public bool Equals(AccessibilitySnapshotResult other)
(Children == other.Children || Children.SequenceEqual(other.Children))));

/// <inheritdoc/>
public override bool Equals(object obj) => obj is AccessibilitySnapshotResult && base.Equals(obj);
public override bool Equals(object obj) => obj is AccessibilitySnapshotResult other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
Expand Down
Loading