From 3bbb8f2fdd2e775d1a359f83ec0d2f76f14eaf3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 12 Feb 2025 09:44:33 -0300 Subject: [PATCH 1/3] Bidi: Implement SetContentAsync --- .../TestExpectations.local.json | 15 --------------- .../PageTests/SetContentTests.cs | 6 +++--- lib/PuppeteerSharp/Bidi/BidiFrame.cs | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json index d7b329a12..1480be245 100644 --- a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json +++ b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json @@ -1515,21 +1515,6 @@ "FAIL" ] }, - { - "comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one", - "testIdPattern": "[page.spec] *Page.setContent*", - "platforms": [ - "darwin", - "linux", - "win32" - ], - "parameters": [ - "webDriverBiDi" - ], - "expectations": [ - "FAIL" - ] - }, { "comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one", "testIdPattern": "[proxy.spec] *", diff --git a/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs b/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs index 8675a3214..8d83daffc 100644 --- a/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs +++ b/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs @@ -7,7 +7,7 @@ namespace PuppeteerSharp.Tests.PageTests { public class SetContentTests : PuppeteerPageBaseTest { - const string ExpectedOutput = "
hello
"; + private const string ExpectedOutput = "
hello
"; public async Task Usage(IBrowser browser) { @@ -65,7 +65,7 @@ public async Task ShouldRespectTimeout() Timeout = 1 })); - Assert.That(exception.Message, Does.Contain("Timeout of 1 ms exceeded")); + Assert.That(exception!.Message, Does.Contain("Timeout of 1 ms exceeded")); } [Test, Retry(2), PuppeteerTest("page.spec", "Page Page.setContent", "should respect default navigation timeout")] @@ -79,7 +79,7 @@ public async Task ShouldRespectDefaultTimeout() var exception = Assert.ThrowsAsync(async () => await Page.SetContentAsync($"")); - Assert.That(exception.Message, Does.Contain("Timeout of 1 ms exceeded")); + Assert.That(exception!.Message, Does.Contain("Timeout of 1 ms exceeded")); } [Test, Retry(2), PuppeteerTest("page.spec", "Page Page.setContent", "should await resources to load")] diff --git a/lib/PuppeteerSharp/Bidi/BidiFrame.cs b/lib/PuppeteerSharp/Bidi/BidiFrame.cs index 195765065..8e2ad5d0e 100644 --- a/lib/PuppeteerSharp/Bidi/BidiFrame.cs +++ b/lib/PuppeteerSharp/Bidi/BidiFrame.cs @@ -97,7 +97,14 @@ internal BidiPage BidiPage public override Task AddScriptTagAsync(AddTagOptions options) => throw new System.NotImplementedException(); /// - public override Task SetContentAsync(string html, NavigationOptions options = null) => throw new System.NotImplementedException(); + public override Task SetContentAsync(string html, NavigationOptions options = null) + { + var waitForLoadTask = WaitForLoadAsync(options); + var waitForNetworkIdleTask = WaitForNetworkIdleAsync(options); + var waitTask = Task.WhenAny([waitForLoadTask, waitForNetworkIdleTask]); + + return Task.WhenAll(SetFrameContentAsync(html), waitTask); + } /// public override async Task GoToAsync(string url, NavigationOptions options) @@ -334,6 +341,15 @@ private void CreateFrameTarget(BrowsingContext browsingContext) }; } + private Task SetFrameContentAsync(string content) + => EvaluateFunctionAsync( + @"""html => {{ + document.open(); + document.write(html); + document.close(); + }}""", + content); + private class Realms(BidiFrameRealm defaultRealm, BidiFrameRealm internalRealm) { public BidiFrameRealm Default { get; } = defaultRealm; From cb2e83c791c89d6324a0bc745c08e6e83e77af25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 12 Feb 2025 11:04:24 -0300 Subject: [PATCH 2/3] Ignore one test --- .../TestExpectations/TestExpectations.local.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json index 1480be245..37b461804 100644 --- a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json +++ b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json @@ -1814,5 +1814,20 @@ "expectations": [ "FAIL" ] + }, + { + "comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one", + "testIdPattern": "[page.spec] *Page.setContent*should await resources to load", + "platforms": [ + "darwin", + "linux", + "win32" + ], + "parameters": [ + "webDriverBiDi" + ], + "expectations": [ + "FAIL" + ] } ] From c9c3859fc9133b8ffc88a1527ceb81e7ae72c677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 12 Feb 2025 14:47:29 -0300 Subject: [PATCH 3/3] some progress --- .../PuppeteerTestAttribute.cs | 4 +- .../TestExpectations.local.json | 15 ------ lib/PuppeteerSharp/Bidi/BidiElementHandle.cs | 2 - lib/PuppeteerSharp/Bidi/BidiFrame.cs | 4 +- lib/PuppeteerSharp/Bidi/BidiFrameRealm.cs | 2 +- lib/PuppeteerSharp/Bidi/BidiJSHandle.cs | 13 ++++- lib/PuppeteerSharp/Bidi/BidiRealm.cs | 51 +++++++++++++++++-- lib/PuppeteerSharp/Bidi/Core/Realm.cs | 3 ++ lib/PuppeteerSharp/Cdp/CdpElementHandle.cs | 16 +----- lib/PuppeteerSharp/Cdp/CdpJSHandle.cs | 2 +- lib/PuppeteerSharp/ElementHandle.cs | 16 ++++++ lib/PuppeteerSharp/JSHandle.cs | 2 + 12 files changed, 86 insertions(+), 44 deletions(-) diff --git a/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs b/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs index c8bc6d49c..1b51a2a20 100644 --- a/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs +++ b/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs @@ -22,8 +22,8 @@ public class PuppeteerTestAttribute : NUnitAttribute, IApplyToTest private static TestExpectation[] _localExpectations; private static TestExpectation[] _upstreamExpectations; - public static readonly bool IsChrome = Environment.GetEnvironmentVariable("BROWSER") != "FIREFOX"; - public static readonly bool IsCdp = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROTOCOL")) || Environment.GetEnvironmentVariable("PROTOCOL")!.Equals("cdp"); + public static readonly bool IsChrome = false; + public static readonly bool IsCdp = false; public static readonly HeadlessMode Headless = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HEADLESS_MODE")) ? diff --git a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json index 37b461804..1480be245 100644 --- a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json +++ b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json @@ -1814,20 +1814,5 @@ "expectations": [ "FAIL" ] - }, - { - "comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one", - "testIdPattern": "[page.spec] *Page.setContent*should await resources to load", - "platforms": [ - "darwin", - "linux", - "win32" - ], - "parameters": [ - "webDriverBiDi" - ], - "expectations": [ - "FAIL" - ] } ] diff --git a/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs b/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs index b3fb070ac..a5e077577 100644 --- a/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs +++ b/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs @@ -47,8 +47,6 @@ public static IJSHandle From(RemoteValue value, BidiRealm realm) return new BidiElementHandle(value, realm); } - public override ValueTask DisposeAsync() => throw new System.NotImplementedException(); - public override Task UploadFileAsync(bool resolveFilePaths, params string[] filePaths) => throw new System.NotImplementedException(); public override Task