Skip to content

Commit e3d4f17

Browse files
authored
Bidi: Pass clickablePoint (#2998)
* Bidi: Pass clickablePoint * fix * implement Frames prop * improve prompts * fix
1 parent 7bed981 commit e3d4f17

File tree

8 files changed

+25
-26
lines changed

8 files changed

+25
-26
lines changed

lib/.claude/commands/implement-bidi-feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ In order to do that you will need to:
1616
* You will have to implement the code as close as possible to the original code, but adapted to .NET idioms and practices.
1717
* As part of the task you will need to generate a document explaining the changes you made, and how they relate to the original PR.
1818
* You need to run related tests to ensure everything is working as expected.
19+
* You will need to run the tests using the ENV variables BROWSER=FIREFOX and PROTOCOL=bidi

lib/CLAUDE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,17 @@ Test directory structure demonstrates comprehensive coverage:
390390
### Building and Running Tests
391391

392392
When running tests, always build first and then use the `--no-build` flag to avoid rebuilding during test execution. This provides faster and more reliable test runs:
393+
Always be explicit with the browser and protocol you want to test using ENV variables BROWSER=FIREFOX|CHROME and PROTOCOL=bidi|cdp
393394

394395
```bash
395396
# Build the test project first
396-
dotnet build PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj
397+
BROWSER=FIREFOX PROTOCOL=bidi dotnet build PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj
397398

398399
# Then run tests with --no-build flag
399-
dotnet test PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj --filter "FullyQualifiedName~TestName" --no-build -- NUnit.TestOutputXml=TestResults
400+
BROWSER=CHROME PROTOCOL=bidi dotnet test PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj --filter "FullyQualifiedName~TestName" --no-build -- NUnit.TestOutputXml=TestResults
400401

401402
# Can also chain them together
402-
dotnet build PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj && dotnet test PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj --filter "FullyQualifiedName~TestName" --no-build -- NUnit.TestOutputXml=TestResults
403+
BROWSER=CHROME PROTOCOL=cdp dotnet build PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj && dotnet test PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj --filter "FullyQualifiedName~TestName" --no-build -- NUnit.TestOutputXml=TestResults
403404
```
404405

405406
You can switch between CDP and Bidi by changing the PuppeteerTestAttribute.IsCdp property.

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -735,21 +735,6 @@
735735
"FAIL"
736736
]
737737
},
738-
{
739-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
740-
"testIdPattern": "[jshandle.spec] *.clickablePoint*",
741-
"platforms": [
742-
"darwin",
743-
"linux",
744-
"win32"
745-
],
746-
"parameters": [
747-
"webDriverBiDi"
748-
],
749-
"expectations": [
750-
"FAIL"
751-
]
752-
},
753738
{
754739
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
755740
"testIdPattern": "[jshandle.spec] *.evaluateHandle*",

lib/PuppeteerSharp.Tests/JSHandleTests/ClickablePointTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ namespace PuppeteerSharp.Tests.JSHandleTests
66
{
77
public class ClickablePointTests : PuppeteerPageBaseTest
88
{
9-
public ClickablePointTests() : base()
10-
{
11-
}
12-
139
[Test, PuppeteerTest("jshandle.spec", "JSHandle JSHandle.clickablePoint", "should work")]
1410
public async Task ShouldWork()
1511
{

lib/PuppeteerSharp/Bidi/BidiElementHandle.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ internal class BidiElementHandle(RemoteValue value, BidiRealm realm) : ElementHa
3636
/// </summary>
3737
public RemoteValue Value { get; } = value;
3838

39+
internal BidiJSHandle BidiJSHandle => Handle as BidiJSHandle;
40+
3941
internal override Realm Realm => realm;
4042

4143
internal override CustomQuerySelectorRegistry CustomQuerySelectorRegistry { get; } = new();
@@ -60,13 +62,13 @@ public override async Task<IFrame> ContentFrameAsync()
6062
return;
6163
}").ConfigureAwait(false);
6264

63-
if (handle is not BidiJSHandle bidiHandle)
65+
if (handle is not BidiElementHandle bidiHandle)
6466
{
6567
await handle.DisposeAsync().ConfigureAwait(false);
6668
return null;
6769
}
6870

69-
var value = bidiHandle.RemoteValue;
71+
var value = bidiHandle.BidiJSHandle.RemoteValue;
7072
await handle.DisposeAsync().ConfigureAwait(false);
7173

7274
if (value.Type == "window" && value.Value is WindowProxyProperties windowProxy)

lib/PuppeteerSharp/Bidi/BidiFrame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class BidiFrame : Frame
4040

4141
internal BidiFrame(BidiPage parentPage, BidiFrame parentFrame, BrowsingContext browsingContext)
4242
{
43-
Client = new BidiCdpSession(this, parentPage.BidiBrowser.LoggerFactory);
43+
Client = new BidiCdpSession(this, parentPage?.BidiBrowser?.LoggerFactory ?? parentFrame?.BidiPage?.BidiBrowser?.LoggerFactory);
4444
ParentPage = parentPage;
4545
ParentFrame = parentFrame;
4646
BrowsingContext = browsingContext;

lib/PuppeteerSharp/Bidi/BidiPage.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ internal BidiPage(BidiBrowserContext browserContext, BrowsingContext browsingCon
5757
public override Target Target { get; }
5858

5959
/// <inheritdoc />
60-
public override IFrame[] Frames { get; }
60+
public override IFrame[] Frames
61+
{
62+
get
63+
{
64+
var frames = new List<IFrame> { BidiMainFrame };
65+
for (var i = 0; i < frames.Count; i++)
66+
{
67+
frames.AddRange(frames[i].ChildFrames);
68+
}
69+
70+
return [.. frames];
71+
}
72+
}
6173

6274
/// <inheritdoc />
6375
public override WebWorker[] Workers { get; }

lib/PuppeteerSharp/ElementHandle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,8 @@ private void IntersectBoundingBox(BoundingBox box, decimal width, decimal height
10021002
? Math.Min(height - box.Y, box.Height)
10031003
: Math.Min(height, box.Height + box.Y),
10041004
0);
1005+
box.X = Math.Max(box.X, 0);
1006+
box.Y = Math.Max(box.Y, 0);
10051007
}
10061008
}
10071009
}

0 commit comments

Comments
 (0)