Skip to content

Commit 5d7ac3f

Browse files
committed
Review failing tests and workflow scripts.
1 parent 285acd7 commit 5d7ac3f

7 files changed

Lines changed: 128 additions & 57 deletions

File tree

.github/workflows/patchright_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
$driverVersion = "${{ needs.check-versions.outputs.driver_version }}"
154154
155155
Write-Host "Building Patchright .NET v$targetVersion with driver v$driverVersion" -ForegroundColor Cyan
156-
.\build.ps1 -Cleanup -DriverVersion $driverVersion -PackageVersion $targetVersion
156+
.\build.ps1 -Cleanup -DriverVersion $driverVersion -PackageVersion $targetVersion -IsolatedContext $True
157157
158158
- name: Find NuGet package
159159
id: find_package

.github/workflows/patchright_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ jobs:
4141
4242
if ($driverVersion) {
4343
Write-Host "Running tests with driver version: $driverVersion" -ForegroundColor Cyan
44-
.\test.ps1 -Cleanup -DriverVersion $driverVersion
44+
.\test.ps1 -DriverVersion $driverVersion
4545
} else {
4646
Write-Host "Running tests with default driver version" -ForegroundColor Cyan
47-
.\test.ps1 -Cleanup
47+
.\test.ps1
4848
}
4949
5050
- name: Upload test results

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,5 @@ FodyWeavers.xsd
401401

402402
# Custom
403403
playwright-dotnet/
404-
nuget/
404+
nuget/
405+
patchright.patch

BUGS.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ GotoAsync("data:text/html,") -> GotoAsync("https://www.google.com/blank.html")
3434
[PlaywrightTest("workers.spec.ts", "should have JSHandles for console logs")]
3535
[PlaywrightTest("workers.spec.ts", "should report console logs")]
3636
[PlaywrightTest("workers.spec.ts", "should report errors")]
37+
[PlaywrightTest("workers.spec.ts", "should report console event on the worker")]
38+
[PlaywrightTest("workers.spec.ts", "should report console event on the worker when not listening on page or context")]
3739
[PlaywrightTest("browsercontext-events.spec.ts", "weberror event should work")]
3840

3941
### Websocket Routing (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/30)
@@ -42,34 +44,57 @@ GotoAsync("data:text/html,") -> GotoAsync("https://www.google.com/blank.html")
4244
[PlaywrightTest("page-route-web-socket.spec.ts", "should work without server")]
4345
[PlaywrightTest("page-route-web-socket.spec.ts", "should work with server")]
4446
[PlaywrightTest("page-route-web-socket.spec.ts", "should work with ws.close")]
47+
[PlaywrightTest("page-route-web-socket.spec.ts", "should work with no trailing slash")]
4548

4649
### Mismatching Request Headers (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/30)
4750
[PlaywrightTest("page-network-request.spec.ts", "should report raw headers")]
4851

49-
### Selectors (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/148)
50-
[PlaywrightTest("page-wait-for-selector-1.spec.ts", "should throw when frame is detached")]
51-
[PlaywrightTest("page-wait-for-selector-2.spec.ts", "should throw when frame is detached xpath")]
52-
5352
### Expose Functions (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/144)
5453
[PlaywrightTest("browsercontext-expose-function.spec.ts", "should be callable from-inside addInitScript")]
5554
[PlaywrightTest("browsercontext-expose-function.spec.ts", "exposeBindingHandle should work")]
55+
[PlaywrightTest("browsercontext-expose-function.spec.ts", "expose binding should work")]
5656
[PlaywrightTest("page-expose-function.spec.ts", "exposeBindingHandle should work")]
57+
[PlaywrightTest("page-expose-function.spec.ts", "should work with handles and complex objects")]
5758

5859
### Init Scripts (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/30)
5960
[PlaywrightTest("page-expose-function.spec.ts", "should be callable from-inside addInitScript")]
6061
[PlaywrightTest("popup.spec.ts", "BrowserContext.addInitScript should apply to an in-process popup")]
62+
[PlaywrightTest("popup.spec.ts", "should expose function from browser context")]
63+
[PlaywrightTest("browsercontext-basic.spec.ts", "should disable javascript")]
64+
[PlaywrightTest("page-wait-for-function.spec.tsPageWaitForFunctionTests", "should work when resolved right before execution context disposal")]
65+
[PlaywrightTest("page-add-init-script.spec.ts", "should work with CSP")] --> Routing stops this from failing.
6166

6267
### Atomic Checks (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/145)
6368
[PlaywrightTest("elementhandle-convenience.spec.ts", "innerHTML should be atomic")]
69+
[PlaywrightTest("elementhandle-convenience.spec.ts", "innerText should be atomic")]
6470
[PlaywrightTest("elementhandle-convenience.spec.ts", "getAttribute should be atomic")]
6571
[PlaywrightTest("selector-register.spec.ts", "textContent should be atomic")]
6672

6773
### Add Script Source (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/30)
6874
[PlaywrightTest("page-add-script-tag.spec.ts", "should include sourceURL when path is provided")]
6975
[PlaywrightTest("page-event-pageerror.spec.ts", "should contain sourceURL")]
7076

71-
### Wrong Error Messages (https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/146)
72-
[PlaywrightTest("elementhandle-eval-on-selector.spec.ts", "should throw in case of missing selector")]
73-
[PlaywrightTest("eval-on-selector.spec.ts", "should throw error if no element is found")]
74-
[PlaywrightTest("page-event-crash.spec.ts", "should throw on any action after page crashes")]
77+
### .NET Playwright Assertion Library
78+
All of these tests actually pass if you directly check the value instead of going through the Expect().ToBe* pattern.
79+
80+
[PlaywrightTest("playwright-test/playwright.expect.spec.ts", "should support toBeEnabled")]
81+
[PlaywrightTest("playwright-test/playwright.expect.spec.ts", "should support toBeVisible")]
82+
[PlaywrightTest("page/expect-misc.spec.ts", "strict mode violation error format")]
83+
[PlaywrightTest("page/expect-boolean.spec.ts", "toBeAttached > eventually with not")]
84+
[PlaywrightTest("page/expect-boolean.spec.ts", "toBeAttached > fail")]
85+
[PlaywrightTest("page/expect-boolean.spec.ts", "toBeAttached > fail with not")]
86+
[PlaywrightTest("page/expect-boolean.spec.ts", "toBeAttached > fail with impossible timeout .not")]
87+
[PlaywrightTest("page/expect-boolean.spec.ts", "toBeAttached > over navigation")]
88+
[PlaywrightTest("page/expect-boolean.spec.ts", "toBeAttached > with not")]
89+
[PlaywrightTest("locator-frame.spec.ts", "should not wait for frame")]
90+
[PlaywrightTest("locator-frame.spec.ts", "should not wait for frame 2")]
91+
[PlaywrightTest("locator-frame.spec.ts", "should not wait for frame 3")]
92+
[PlaywrightTest("locator-frame.spec.ts", "should wait for frame to go")]
93+
[PlaywrightTest("locator-query.spec.ts", "should filter by regex with a single quote")]
7594

95+
### Inconsistent Tests
96+
[PlaywrightTest("resource-timing.spec.ts", "should work when serving from memory cache")]
97+
[PlaywrightTest("tracing.spec.ts", "should collect trace with resources, but no js")]
98+
[PlaywrightTest("tracing.spec.ts", "should respect tracesDir and name")]
99+
[PlaywrightTest("page-wait-for-selector-1.spec.ts", "should report logs while waiting for visible")]
100+
[PlaywrightTest("page-wait-for-selector-1.spec.ts", "should report logs while waiting for hidden")]

Patchright.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
Console.WriteLine();
3030

3131
const string playwrightPath = "playwright-dotnet";
32-
var driverVersion = args.Length > 0 ? args[0] : null;
33-
var packageVersion = args.Length > 1 ? args[1] : null;
32+
var isolatedContextDefaultValue = args.Length > 0 ? bool.Parse(args[0]) : true;
33+
var driverVersion = args.Length > 1 ? args[1] : null;
34+
var packageVersion = args.Length > 2 ? args[2] : null;
3435

3536
if (!Directory.Exists(playwrightPath))
3637
{
@@ -270,14 +271,14 @@ void PatchWorker()
270271

271272
Console.WriteLine($"Patching Worker file: {workerPath}");
272273

273-
File.WriteAllText(workerPath, AddIsolatedContextToMethods(workerCode, "Worker", methodNamesToPatch));
274+
File.WriteAllText(workerPath, AddIsolatedContextToMethods(workerCode, "Worker", isolatedContextDefaultValue, methodNamesToPatch));
274275

275276
var workerGeneratedInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Generated", "IWorker.cs");
276277
var workerGeneratedInterfaceCode = File.ReadAllText(workerGeneratedInterfacePath);
277278

278279
Console.WriteLine($"Patching generated IWorker file: {workerGeneratedInterfacePath}");
279280

280-
File.WriteAllText(workerGeneratedInterfacePath, AddIsolatedContextToMethods(workerGeneratedInterfaceCode, "IWorker", methodNamesToPatch));
281+
File.WriteAllText(workerGeneratedInterfacePath, AddIsolatedContextToMethods(workerGeneratedInterfaceCode, "IWorker", isolatedContextDefaultValue, methodNamesToPatch));
281282
}
282283

283284
// Add isolatedContext parameter to JSHandle methods.
@@ -290,21 +291,21 @@ void PatchJSHandle()
290291

291292
Console.WriteLine($"Patching JSHandle file: {jsHandlePath}");
292293

293-
File.WriteAllText(jsHandlePath, AddIsolatedContextToMethods(jsHandleCode, "JSHandle", methodNamesToPatch));
294+
File.WriteAllText(jsHandlePath, AddIsolatedContextToMethods(jsHandleCode, "JSHandle", isolatedContextDefaultValue, methodNamesToPatch));
294295

295296
var jsHandleGeneratedInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Generated", "IJSHandle.cs");
296297
var jsHandleGeneratedInterfaceCode = File.ReadAllText(jsHandleGeneratedInterfacePath);
297298

298299
Console.WriteLine($"Patching generated IJSHandle file: {jsHandleGeneratedInterfacePath}");
299300

300-
File.WriteAllText(jsHandleGeneratedInterfacePath, AddIsolatedContextToMethods(jsHandleGeneratedInterfaceCode, "IJSHandle", methodNamesToPatch));
301+
File.WriteAllText(jsHandleGeneratedInterfacePath, AddIsolatedContextToMethods(jsHandleGeneratedInterfaceCode, "IJSHandle", isolatedContextDefaultValue, methodNamesToPatch));
301302

302303
var jsHandleSupplementsInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Supplements", "IJSHandle.cs");
303304
var jsHandleSupplementsInterfaceCode = File.ReadAllText(jsHandleSupplementsInterfacePath);
304305

305306
Console.WriteLine($"Patching supplements IJSHandle file: {jsHandleSupplementsInterfacePath}");
306307

307-
var newJsHandleSupplementsInterfaceCode = AddIsolatedContextToMethods(jsHandleSupplementsInterfaceCode, "IJSHandle", methodNamesToPatch);
308+
var newJsHandleSupplementsInterfaceCode = AddIsolatedContextToMethods(jsHandleSupplementsInterfaceCode, "IJSHandle", isolatedContextDefaultValue, methodNamesToPatch);
308309
File.WriteAllText(jsHandleSupplementsInterfacePath, newJsHandleSupplementsInterfaceCode.Replace("EvaluateAsync{T}(string, object)", "EvaluateAsync{T}(string, object, bool)"));
309310
}
310311

@@ -319,21 +320,21 @@ void PatchFrame()
319320

320321
Console.WriteLine($"Patching Frame file: {framePath}");
321322

322-
File.WriteAllText(framePath, AddIsolatedContextToMethods(frameCode, "Frame", methodNamesToPatch));
323+
File.WriteAllText(framePath, AddIsolatedContextToMethods(frameCode, "Frame", isolatedContextDefaultValue, methodNamesToPatch));
323324

324325
var frameGeneratedInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Generated", "IFrame.cs");
325326
var frameGeneratedInterfaceCode = File.ReadAllText(frameGeneratedInterfacePath);
326327

327328
Console.WriteLine($"Patching generated IFrame file: {frameGeneratedInterfacePath}");
328329

329-
File.WriteAllText(frameGeneratedInterfacePath, AddIsolatedContextToMethods(frameGeneratedInterfaceCode, "IFrame", methodNamesToPatch));
330+
File.WriteAllText(frameGeneratedInterfacePath, AddIsolatedContextToMethods(frameGeneratedInterfaceCode, "IFrame", isolatedContextDefaultValue, methodNamesToPatch));
330331

331332
var frameSupplementsInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Supplements", "IFrame.cs");
332333
var frameSupplementsInterfaceCode = File.ReadAllText(frameSupplementsInterfacePath);
333334

334335
Console.WriteLine($"Patching supplements IFrame file: {frameSupplementsInterfacePath}");
335336

336-
File.WriteAllText(frameSupplementsInterfacePath, AddIsolatedContextToMethods(frameSupplementsInterfaceCode, "IFrame", methodNamesToPatch));
337+
File.WriteAllText(frameSupplementsInterfacePath, AddIsolatedContextToMethods(frameSupplementsInterfaceCode, "IFrame", isolatedContextDefaultValue, methodNamesToPatch));
337338
}
338339

339340
// Add isolatedContext parameter to Locator methods.
@@ -346,21 +347,21 @@ void PatchLocator()
346347

347348
Console.WriteLine($"Patching Locator file: {locatorPath}");
348349

349-
File.WriteAllText(locatorPath, AddIsolatedContextToMethods(locatorCode, "Locator", methodNamesToPatch));
350+
File.WriteAllText(locatorPath, AddIsolatedContextToMethods(locatorCode, "Locator", isolatedContextDefaultValue, methodNamesToPatch));
350351

351352
var locatorGeneratedInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Generated", "ILocator.cs");
352353
var locatorGeneratedInterfaceCode = File.ReadAllText(locatorGeneratedInterfacePath);
353354

354355
Console.WriteLine($"Patching generated ILocator file: {locatorGeneratedInterfacePath}");
355356

356-
File.WriteAllText(locatorGeneratedInterfacePath, AddIsolatedContextToMethods(locatorGeneratedInterfaceCode, "ILocator", methodNamesToPatch));
357+
File.WriteAllText(locatorGeneratedInterfacePath, AddIsolatedContextToMethods(locatorGeneratedInterfaceCode, "ILocator", isolatedContextDefaultValue, methodNamesToPatch));
357358

358359
var locatorSupplementsInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Supplements", "ILocator.cs");
359360
var locatorSupplementsInterfaceCode = File.ReadAllText(locatorSupplementsInterfacePath);
360361

361362
Console.WriteLine($"Patching supplements ILocator file: {locatorSupplementsInterfacePath}");
362363

363-
File.WriteAllText(locatorSupplementsInterfacePath, AddIsolatedContextToMethods(locatorSupplementsInterfaceCode, "ILocator", methodNamesToPatch));
364+
File.WriteAllText(locatorSupplementsInterfacePath, AddIsolatedContextToMethods(locatorSupplementsInterfaceCode, "ILocator", isolatedContextDefaultValue, methodNamesToPatch));
364365
}
365366

366367
// Add isolatedContext parameter to Page methods.
@@ -373,7 +374,7 @@ void PatchPage()
373374

374375
Console.WriteLine($"Patching Page file: {pagePath}");
375376

376-
File.WriteAllText(pagePath, AddIsolatedContextToMethods(pageCode, "Page", methodNamesToPatch));
377+
File.WriteAllText(pagePath, AddIsolatedContextToMethods(pageCode, "Page", isolatedContextDefaultValue, methodNamesToPatch));
377378

378379
// Read the code again after the isolated context changes have been applied.
379380
pageCode = File.ReadAllText(pagePath);
@@ -456,14 +457,14 @@ await RouteAsync("**/*", async route =>
456457

457458
Console.WriteLine($"Patching generated IPage file: {pageGeneratedInterfacePath}");
458459

459-
File.WriteAllText(pageGeneratedInterfacePath, AddIsolatedContextToMethods(pageGeneratedInterfaceCode, "IPage", methodNamesToPatch));
460+
File.WriteAllText(pageGeneratedInterfacePath, AddIsolatedContextToMethods(pageGeneratedInterfaceCode, "IPage", isolatedContextDefaultValue, methodNamesToPatch));
460461

461462
var pageSupplementsInterfacePath = Path.Combine(playwrightPath, "src", "Playwright", "API", "Supplements", "IPage.cs");
462463
var pageSupplementsInterfaceCode = File.ReadAllText(pageSupplementsInterfacePath);
463464

464465
Console.WriteLine($"Patching supplements IPage file: {pageSupplementsInterfacePath}");
465466

466-
File.WriteAllText(pageSupplementsInterfacePath, AddIsolatedContextToMethods(pageSupplementsInterfaceCode, "IPage", methodNamesToPatch));
467+
File.WriteAllText(pageSupplementsInterfacePath, AddIsolatedContextToMethods(pageSupplementsInterfaceCode, "IPage", isolatedContextDefaultValue, methodNamesToPatch));
467468
}
468469

469470
// Add route injection to BrowserContext class and call from relevant methods.
@@ -870,7 +871,7 @@ inv.Expression is SimpleNameSyntax simpleName &&
870871

871872
// Method to add isolatedContext parameter to specified methods provided.
872873
// This will also patch pass-through calls to private methods as needed and add the dictionary entry to SendMessageToServerAsync calls.
873-
static string AddIsolatedContextToMethods(string code, string typeName, IEnumerable<string> methodNames)
874+
static string AddIsolatedContextToMethods(string code, string typeName, bool defaultValue, IEnumerable<string> methodNames)
874875
{
875876
var tree = CSharpSyntaxTree.ParseText(code);
876877
var root = tree.GetRoot();
@@ -1011,7 +1012,7 @@ static string AddIsolatedContextToMethods(string code, string typeName, IEnumera
10111012
SyntaxFactory.Token(SyntaxKind.EqualsToken)
10121013
.WithLeadingTrivia(SyntaxFactory.Space)
10131014
.WithTrailingTrivia(SyntaxFactory.Space),
1014-
SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression)));
1015+
defaultValue ? SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression) : SyntaxFactory.LiteralExpression(SyntaxKind.FalseLiteralExpression)));
10151016

10161017
// Add leading space if there are existing parameters.
10171018
var newParameterList = currentMethod.ParameterList.Parameters.Count > 0

build.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
Specific driver version to use
1111
.PARAMETER PackageVersion
1212
Target package version to build (overrides Version.props)
13+
.PARAMETER IsolatedContextDefault
14+
The default isolated context behavior to use when running the patch.
1315
.EXAMPLE
1416
.\build.ps1
1517
.\build.ps1 -Cleanup
1618
.\build.ps1 -Cleanup -DriverVersion 1.57.0 -PackageVersion 1.57.0
19+
.\build.ps1 -Cleanup -DriverVersion 1.57.0 -PackageVersion 1.57.0 -IsolatedContextDefault $false
1720
#>
1821

1922
param(
2023
[switch]$Cleanup,
2124
[string]$DriverVersion,
22-
[string]$PackageVersion
25+
[string]$PackageVersion,
26+
[bool]$IsolatedContextDefault = $true # Default to true, can be overridden for unit tests
2327
)
2428

2529
$ErrorActionPreference = "Stop"
@@ -123,12 +127,8 @@ finally {
123127

124128
# Run Patchright
125129
Write-Host "`nRunning Patchright..." -ForegroundColor Cyan
126-
if ($DriverVersion && $PackageVersion) {
127-
dotnet run .\Patchright.cs $DriverVersion $PackageVersion
128-
}
129-
else {
130-
dotnet run .\Patchright.cs
131-
}
130+
dotnet run .\Patchright.cs $IsolatedContextDefault $DriverVersion $PackageVersion
131+
132132
if ($LASTEXITCODE -ne 0) {
133133
Write-Error "Failed to run Patchright"
134134
exit 1

0 commit comments

Comments
 (0)