From 1a248347785e03fbb50575ce18b7bcb2df4d5083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Sat, 28 Mar 2026 15:21:31 -0300 Subject: [PATCH] Fix page-accessibility tests: broken Equals override and outdated expectations The root cause was AccessibilitySnapshotResult.Equals(object) calling base.Equals(obj) (reference equality) instead of the typed Equals method, causing all NUnit Is.EqualTo() assertions to fail. Also updates test expectations to match upstream: autofocus wait, Chromium role changes (img->image, vertical orientation on menu), Multiline on contenteditable textbox, and adds missing tests (title, aria-invalid). Removes incorrect browser skip annotations on tests that upstream runs on all browsers. Closes #89 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../PageAccessibilityContentEditableTests.cs | 12 ++-- .../PageAccessibilityTests.cs | 70 +++++++++++++++---- .../Models/AccessibilitySnapshotResult.cs | 2 +- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/PlaywrightSharp.Tests/PageAccessibilityContentEditableTests.cs b/src/PlaywrightSharp.Tests/PageAccessibilityContentEditableTests.cs index d3a192056..5a4c77949 100644 --- a/src/PlaywrightSharp.Tests/PageAccessibilityContentEditableTests.cs +++ b/src/PlaywrightSharp.Tests/PageAccessibilityContentEditableTests.cs @@ -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(@" @@ -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(@" @@ -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(@" diff --git a/src/PlaywrightSharp.Tests/PageAccessibilityTests.cs b/src/PlaywrightSharp.Tests/PageAccessibilityTests.cs index fbabff1fb..61c85a83b 100644 --- a/src/PlaywrightSharp.Tests/PageAccessibilityTests.cs +++ b/src/PlaywrightSharp.Tests/PageAccessibilityTests.cs @@ -31,6 +31,9 @@ await Page.SetContentAsync(@" "); + // autofocus happens after a delay in chrome these days + await Page.WaitForFunctionAsync("() => document.activeElement.hasAttribute('autofocus')"); + AccessibilitySnapshotResult nodeToCheck; if (TestConstants.IsFirefox) @@ -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() }; @@ -213,7 +216,7 @@ public async Task ShouldWorkWithRegularRext() [Test, Timeout(TestConstants.DefaultTestTimeout)] public async Task RoleDescription() { - await Page.SetContentAsync("
Hi
"); + await Page.SetContentAsync("

Hi

"); var snapshot = (await Page.Accessibility.SnapshotAsync()); Assert.That(snapshot.Children.First().Roledescription, Is.EqualTo("foo")); } @@ -231,9 +234,10 @@ public async Task Orientation() [Test, Timeout(TestConstants.DefaultTestTimeout)] public async Task Autocomplete() { - await Page.SetContentAsync("
hi
"); + await Page.SetContentAsync("
hi
"); 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")] @@ -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(@"
@@ -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" } } @@ -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: " } } }; @@ -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(); @@ -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(@" + This is the title +
This is the content
+ "); + 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("WHO WE ARE"); + + 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); + } } } diff --git a/src/PlaywrightSharp/Contracts/Models/AccessibilitySnapshotResult.cs b/src/PlaywrightSharp/Contracts/Models/AccessibilitySnapshotResult.cs index f7d994128..610ab0dce 100644 --- a/src/PlaywrightSharp/Contracts/Models/AccessibilitySnapshotResult.cs +++ b/src/PlaywrightSharp/Contracts/Models/AccessibilitySnapshotResult.cs @@ -48,7 +48,7 @@ public bool Equals(AccessibilitySnapshotResult other) (Children == other.Children || Children.SequenceEqual(other.Children)))); /// - public override bool Equals(object obj) => obj is AccessibilitySnapshotResult && base.Equals(obj); + public override bool Equals(object obj) => obj is AccessibilitySnapshotResult other && Equals(other); /// public override int GetHashCode()