From 04386d8372823cd0ac3ece045c84619300af2504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Sat, 28 Mar 2026 15:21:13 -0300 Subject: [PATCH] Fix emulation-focus headful test failures (#119) The emulation-focus tests were marked as expected failures in headful mode, but the Playwright driver already handles focus emulation via Emulation.setFocusEmulationEnabled (Chromium) and Emulation.setActiveAndFocused (WebKit). The tests should pass in headful mode as they do in upstream Playwright. Changes: - Fix assertion order in ShouldFocusPopupsByDefault to match upstream (check popup focus before page focus) - Add Firefox headful skip for ShouldChangeFocusedIframe matching upstream's it.skip for headed Firefox losing focus - Add IsHeadless property to TestConstants for runtime headless checks - Remove [emulation-focus.spec.ts] expected failure entry from TestExpectations Co-Authored-By: Claude Opus 4.6 (1M context) --- .../TestExpectations/TestExpectations.local.json | 6 ------ src/PlaywrightSharp.Tests/EmulationFocusTests.cs | 7 ++++++- src/PlaywrightSharp.Tests/TestConstants.cs | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json b/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json index 42a60d767..75c4f3ded 100644 --- a/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json +++ b/src/PlaywrightSharp.Nunit/TestExpectations/TestExpectations.local.json @@ -197,12 +197,6 @@ "parameters": ["headful"], "expectations": ["FAIL"] }, - { - "testIdPattern": "[emulation-focus.spec.ts] *", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["headful"], - "expectations": ["FAIL"] - }, { "testIdPattern": "[eval-on-selector-all.spec.ts] *", "platforms": ["darwin", "linux", "win32"], diff --git a/src/PlaywrightSharp.Tests/EmulationFocusTests.cs b/src/PlaywrightSharp.Tests/EmulationFocusTests.cs index 03e9bcc8b..53007ca04 100644 --- a/src/PlaywrightSharp.Tests/EmulationFocusTests.cs +++ b/src/PlaywrightSharp.Tests/EmulationFocusTests.cs @@ -36,8 +36,8 @@ await TaskUtils.WhenAll( var popup = popupTask.Result; - Assert.That(await Page.EvaluateAsync("document.hasFocus()"), Is.True); Assert.That(await popup.EvaluateAsync("document.hasFocus()"), Is.True); + Assert.That(await Page.EvaluateAsync("document.hasFocus()"), Is.True); } [PlaywrightTest("emulation-focus.spec.ts", "should provide target for keyboard events")] @@ -128,6 +128,11 @@ public void ShouldNotAffectScreenshots() [Test, Timeout(TestConstants.DefaultTestTimeout)] public async Task ShouldChangeFocusedIframe() { + if (TestConstants.IsFirefox && !TestConstants.IsHeadless) + { + Assert.Ignore("Headed Firefox might lose focus"); + } + await Page.GoToAsync(TestConstants.EmptyPage); var (frame1, frame2) = await TaskUtils.WhenAll( diff --git a/src/PlaywrightSharp.Tests/TestConstants.cs b/src/PlaywrightSharp.Tests/TestConstants.cs index 4804ab2cb..8c177d4c2 100644 --- a/src/PlaywrightSharp.Tests/TestConstants.cs +++ b/src/PlaywrightSharp.Tests/TestConstants.cs @@ -117,6 +117,7 @@ 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 = Convert.ToBoolean(Environment.GetEnvironmentVariable("HEADLESS") ?? "true"); public static readonly IEnumerable NestedFramesDumpResult = new List() {