From fa7d9d4a0b26ab3ec1abf61cae5492b290a04082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Sat, 28 Mar 2026 15:20:49 -0300 Subject: [PATCH] Fix page-click.spec.ts headful test failures by matching upstream Update tests to match upstream Playwright behavior for headful mode: - ShouldClickOnCheckboxInputAndToggle: filter mouseout/mouseleave events in headful mode (mouse can leave the viewport in headed browsers) - ShouldWaitForSelectToBeEnabled: use mousedown with preventDefault() instead of onclick to prevent dropdown from opening in headful mode - ShouldWaitForStablePosition: add rafraf call before clicking to let Firefox kick in the CSS animation - ShouldClickTheButtonWhenWindowInnerWidthIsCorrupted: fix typo (innerWith -> innerWidth) and use Object.defineProperty per upstream Add TestConstants.IsHeadless helper for headful-conditional test logic. Remove overly broad [page-click.spec.ts] * headful expected-failure entry. Closes #124 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../TestExpectations.local.json | 6 ----- src/PlaywrightSharp.Tests/PageClickTests.cs | 22 ++++++++++++++++--- src/PlaywrightSharp.Tests/TestConstants.cs | 2 ++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json b/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json index 42a60d767..255a91f9b 100644 --- a/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json +++ b/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json @@ -227,12 +227,6 @@ "parameters": ["headful"], "expectations": ["FAIL"] }, - { - "testIdPattern": "[page-click.spec.ts] *", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["headful"], - "expectations": ["FAIL"] - }, { "testIdPattern": "[page-fill.spec.ts] *", "platforms": ["darwin", "linux", "win32"], diff --git a/src/PlaywrightSharp.Tests/PageClickTests.cs b/src/PlaywrightSharp.Tests/PageClickTests.cs index 58dc3a712..3e3756723 100644 --- a/src/PlaywrightSharp.Tests/PageClickTests.cs +++ b/src/PlaywrightSharp.Tests/PageClickTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Threading.Tasks; using NUnit.Framework; using PlaywrightSharp.Helpers; @@ -261,7 +262,13 @@ public async Task ShouldClickOnCheckboxInputAndToggle() Assert.That(await Page.EvaluateAsync("result.check"), Is.Null); await Page.ClickAsync("input#agree"); Assert.That(await Page.EvaluateAsync("result.check"), Is.True); - Assert.That(await Page.EvaluateAsync("result.events"), Is.EqualTo(new[] { + var events = await Page.EvaluateAsync("result.events"); + if (!TestConstants.IsHeadless) + { + events = events.Where(e => e != "mouseout" && e != "mouseleave").ToArray(); + } + + Assert.That(events, Is.EqualTo(new[] { "mouseover", "mouseenter", "mousemove", @@ -549,6 +556,8 @@ await Page.EvalOnSelectorAsync("button", @"button => { document.body.style.margin = '0'; }"); + // rafraf for Firefox to kick in the animation. + await Page.EvaluateAsync("() => new Promise(f => requestAnimationFrame(() => requestAnimationFrame(f)))"); await Page.ClickAsync("button"); Assert.That(await Page.EvaluateAsync("window.result"), Is.EqualTo("Clicked")); Assert.That(await Page.EvaluateAsync("pageX"), Is.EqualTo(300)); @@ -642,7 +651,14 @@ public async Task ShouldWaitForInputToBeEnabled() [Test, Timeout(TestConstants.DefaultTestTimeout)] public async Task ShouldWaitForSelectToBeEnabled() { - await Page.SetContentAsync(""); + await Page.SetContentAsync(@" + + "); var clickTask = Page.ClickAsync("select"); await GiveItAChanceToClick(Page); Assert.That(await Page.EvaluateAsync("window.__CLICKED"), Is.Null); @@ -894,7 +910,7 @@ await Page.SetContentAsync($@" public async Task ShouldClickTheButtonWhenWindowInnerWidthIsCorrupted() { await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html"); - await Page.EvaluateAsync(@"() => window.innerWith = 0"); + await Page.EvaluateAsync(@"() => Object.defineProperty(window, 'innerWidth', { value: 0 })"); await Page.ClickAsync("button"); Assert.That(await Page.EvaluateAsync("result"), Is.EqualTo("Clicked")); diff --git a/src/PlaywrightSharp.Tests/TestConstants.cs b/src/PlaywrightSharp.Tests/TestConstants.cs index 4804ab2cb..00352cf3a 100644 --- a/src/PlaywrightSharp.Tests/TestConstants.cs +++ b/src/PlaywrightSharp.Tests/TestConstants.cs @@ -117,6 +117,8 @@ internal static Task LaunchDefaultHeadful( internal static readonly bool IsChromium = Product.Equals(ChromiumProduct, StringComparison.OrdinalIgnoreCase); internal static readonly bool IsMacOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); internal static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + internal static readonly bool IsHeadless = !string.Equals( + Environment.GetEnvironmentVariable("HEADLESS"), "false", StringComparison.OrdinalIgnoreCase); public static readonly IEnumerable NestedFramesDumpResult = new List() {