Skip to content

Commit cc93375

Browse files
authored
Bidi: Idle override (#2979)
1 parent e638610 commit cc93375

File tree

7 files changed

+36
-76
lines changed

7 files changed

+36
-76
lines changed

.github/workflows/dotnet.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
browser: FIREFOX
5555
mode: headless
5656
protocol: webdriverbidi
57+
- os: ubuntu-latest
58+
browser: FIREFOX
59+
mode: headful
60+
protocol: webdriverbidi
5761
steps:
5862
- uses: actions/checkout@v3
5963
- name: Setup .NET Core

lib/CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,26 @@ Test directory structure demonstrates comprehensive coverage:
385385
- wwwroot directory with test fixtures
386386
- Asset serving for test scenarios
387387

388+
## Development Best Practices
389+
390+
### Building and Running Tests
391+
392+
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+
394+
```bash
395+
# Build the test project first
396+
dotnet build PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj
397+
398+
# Then run tests with --no-build flag
399+
dotnet test PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj --filter "FullyQualifiedName~TestName" --no-build -- NUnit.TestOutputXml=TestResults
400+
401+
# 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+
```
404+
405+
You can switch between CDP and Bidi by changing the PuppeteerTestAttribute.IsCdp property.
406+
You can switch between Chrome and Firefox by changing the PuppeteerTestAttribute.IsChrome property.
407+
388408
## Utilities and Helpers
389409

390410
### Helper Classes (`Helpers/`)

lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class PuppeteerTestAttribute : NUnitAttribute, IApplyToTest
2222
private static TestExpectation[] _localExpectations;
2323
private static TestExpectation[] _upstreamExpectations;
2424

25-
public static readonly bool IsChrome = Environment.GetEnvironmentVariable("BROWSER") != "FIREFOX";
26-
public static readonly bool IsCdp = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROTOCOL")) || Environment.GetEnvironmentVariable("PROTOCOL")!.Equals("cdp");
25+
public static readonly bool IsChrome = false;
26+
public static readonly bool IsCdp = false;
2727

2828
public static readonly HeadlessMode Headless =
2929
string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HEADLESS_MODE")) ?

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

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -780,51 +780,6 @@
780780
"FAIL"
781781
]
782782
},
783-
{
784-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
785-
"testIdPattern": "[golden-utils] *",
786-
"platforms": [
787-
"darwin",
788-
"linux",
789-
"win32"
790-
],
791-
"parameters": [
792-
"webDriverBiDi"
793-
],
794-
"expectations": [
795-
"FAIL"
796-
]
797-
},
798-
{
799-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
800-
"testIdPattern": "[headful.spec] *",
801-
"platforms": [
802-
"darwin",
803-
"linux",
804-
"win32"
805-
],
806-
"parameters": [
807-
"webDriverBiDi"
808-
],
809-
"expectations": [
810-
"FAIL"
811-
]
812-
},
813-
{
814-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
815-
"testIdPattern": "[idle_override.spec] *",
816-
"platforms": [
817-
"darwin",
818-
"linux",
819-
"win32"
820-
],
821-
"parameters": [
822-
"webDriverBiDi"
823-
],
824-
"expectations": [
825-
"FAIL"
826-
]
827-
},
828783
{
829784
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
830785
"testIdPattern": "[acceptInsecureCerts.spec] *",
@@ -870,21 +825,6 @@
870825
"FAIL"
871826
]
872827
},
873-
{
874-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
875-
"testIdPattern": "[jshandle.spec] *.asElement*",
876-
"platforms": [
877-
"darwin",
878-
"linux",
879-
"win32"
880-
],
881-
"parameters": [
882-
"webDriverBiDi"
883-
],
884-
"expectations": [
885-
"FAIL"
886-
]
887-
},
888828
{
889829
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
890830
"testIdPattern": "[jshandle.spec] *.clickablePoint*",

lib/PuppeteerSharp.Tests/ElementHandleTests/ContentFrameTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public async Task ShouldWork()
2727
[Test, PuppeteerTest("elementhandle.spec", "PuppeteerSharp", "should work headful")]
2828
public async Task ShouldWorkHeadful()
2929
{
30-
await using var Browser = await Puppeteer.LaunchAsync(_headfulOptions);
31-
await using var Page = await Browser.NewPageAsync();
32-
await Page.GoToAsync($"{TestConstants.ServerUrl}/frame-example.html");
33-
var elementHandle = await Page.QuerySelectorAsync("iframe");
30+
await using var browser = await Puppeteer.LaunchAsync(_headfulOptions);
31+
await using var page = await browser.NewPageAsync();
32+
await page.GoToAsync($"{TestConstants.ServerUrl}/frame-example.html");
33+
var elementHandle = await page.QuerySelectorAsync("iframe");
3434
var frame = await elementHandle.ContentFrameAsync();
35-
Assert.That(frame, Is.EqualTo(Page.FirstChildFrame()));
35+
Assert.That(frame, Is.EqualTo(page.FirstChildFrame()));
3636
}
3737
}
3838
}

lib/PuppeteerSharp.Tests/IdleOverrideTests/IdleOverrideTests.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ namespace PuppeteerSharp.Tests.IdleOverrideTests
66
{
77
public class IdleOverrideTests : PuppeteerPageBaseTest
88
{
9-
public IdleOverrideTests() : base()
10-
{
11-
}
12-
139
private async Task<string> GetIdleStateAsync()
1410
{
1511
var stateElement = await Page.QuerySelectorAsync("#state");
@@ -31,10 +27,9 @@ public async Task ChangingIdleStateEmulationCausesChangeOfTheIdleDetectorState()
3127
{
3228
await Context.OverridePermissionsAsync(
3329
TestConstants.ServerUrl + "/idle-detector.html",
34-
new[]
35-
{
36-
OverridePermission.IdleDetection,
37-
});
30+
[
31+
OverridePermission.IdleDetection
32+
]);
3833

3934
await Page.GoToAsync(TestConstants.ServerUrl + "/idle-detector.html");
4035

lib/PuppeteerSharp/Bidi/BidiPage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public override async Task BringToFrontAsync()
9696
public override Task EmulateTimezoneAsync(string timezoneId) => throw new NotImplementedException();
9797

9898
/// <inheritdoc />
99-
public override Task EmulateIdleStateAsync(EmulateIdleOverrides idleOverrides = null) => throw new NotImplementedException();
99+
public override Task EmulateIdleStateAsync(EmulateIdleOverrides idleOverrides = null)
100+
=> _cdpEmulationManager.EmulateIdleStateAsync(idleOverrides);
100101

101102
/// <inheritdoc />
102103
public override Task EmulateCPUThrottlingAsync(decimal? factor = null) => throw new NotImplementedException();

0 commit comments

Comments
 (0)