Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Jan 30, 2025
1 parent b3747fc commit 86fea44
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 70 deletions.
10 changes: 5 additions & 5 deletions src/Playwright.MSTest/BrowserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ private BrowserService(IBrowser browser)
Browser = browser;
}

public static Task<BrowserService> Register(WorkerAwareTest test, IBrowserType browserType, PlaywrightConnectOptions? connectOptions)
public static Task<BrowserService> Register(WorkerAwareTest test, IBrowserType browserType, (string, BrowserTypeConnectOptions?)? connectOptions)
{
return test.RegisterService("Browser", async () => new BrowserService(await CreateBrowser(browserType, connectOptions).ConfigureAwait(false)));
}

private static async Task<IBrowser> CreateBrowser(IBrowserType browserType, PlaywrightConnectOptions? connectOptions)
private static async Task<IBrowser> CreateBrowser(IBrowserType browserType, (string WSEndpoint, BrowserTypeConnectOptions? Options)? connectOptions)
{
if (connectOptions != null)
if (connectOptions.HasValue && connectOptions.Value.WSEndpoint != null)
{
var options = new BrowserTypeConnectOptions(connectOptions);
var options = new BrowserTypeConnectOptions(connectOptions?.Options ?? new());
var headers = options.Headers?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) ?? [];
headers.Add("x-playwright-launch-options", JsonSerializer.Serialize(PlaywrightSettingsProvider.LaunchOptions, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }));
options.Headers = headers;
return await browserType.ConnectAsync(connectOptions.WSEndpoint, options).ConfigureAwait(false);
return await browserType.ConnectAsync(connectOptions.Value.WSEndpoint, options).ConfigureAwait(false);
}

var legacyBrowser = await ConnectBasedOnEnv(browserType);
Expand Down
5 changes: 1 addition & 4 deletions src/Playwright.MSTest/BrowserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,5 @@ public async Task BrowserTearDown()
Browser = null!;
}

public virtual Task<PlaywrightConnectOptions?> ConnectOptionsAsync()
{
return Task.FromResult<PlaywrightConnectOptions?>(null);
}
public virtual Task<(string, BrowserTypeConnectOptions?)?> ConnectOptionsAsync() => null!;
}
10 changes: 5 additions & 5 deletions src/Playwright.NUnit/BrowserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ private BrowserService(IBrowser browser)
Browser = browser;
}

public static Task<BrowserService> Register(WorkerAwareTest test, IBrowserType browserType, PlaywrightConnectOptions? connectOptions)
public static Task<BrowserService> Register(WorkerAwareTest test, IBrowserType browserType, (string, BrowserTypeConnectOptions?)? connectOptions)
{
return test.RegisterService("Browser", async () => new BrowserService(await CreateBrowser(browserType, connectOptions).ConfigureAwait(false)));
}

private static async Task<IBrowser> CreateBrowser(IBrowserType browserType, PlaywrightConnectOptions? connectOptions)
private static async Task<IBrowser> CreateBrowser(IBrowserType browserType, (string WSEndpoint, BrowserTypeConnectOptions? Options)? connectOptions)
{
if (connectOptions != null)
if (connectOptions.HasValue && connectOptions.Value.WSEndpoint != null)
{
var options = new BrowserTypeConnectOptions(connectOptions);
var options = new BrowserTypeConnectOptions(connectOptions?.Options ?? new());
var headers = options.Headers?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) ?? [];
headers.Add("x-playwright-launch-options", JsonSerializer.Serialize(PlaywrightSettingsProvider.LaunchOptions, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }));
options.Headers = headers;
return await browserType.ConnectAsync(connectOptions.WSEndpoint, options).ConfigureAwait(false);
return await browserType.ConnectAsync(connectOptions.Value.WSEndpoint, options).ConfigureAwait(false);
}

var legacyBrowser = await ConnectBasedOnEnv(browserType);
Expand Down
5 changes: 1 addition & 4 deletions src/Playwright.NUnit/BrowserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ public async Task BrowserTearDown()
Browser = null!;
}

public virtual Task<PlaywrightConnectOptions?> ConnectOptionsAsync()
{
return Task.FromResult<PlaywrightConnectOptions?>(null);
}
public virtual Task<(string, BrowserTypeConnectOptions?)?> ConnectOptionsAsync() => null!;
}
30 changes: 0 additions & 30 deletions src/Playwright.TestAdapter/PlaywrightConnectOptions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Playwright.TestingHarnessTest/tests/baseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const test = base.extend<{
for (const server of servers)
await server.close();
},
runTest: async ({ }, use, testInfo) => {
runTest: async ({ testMode }, use, testInfo) => {
const testResults: RunResult[] = [];
await use(async (files, command, env) => {
const testDir = testInfo.outputPath();
Expand Down
7 changes: 3 additions & 4 deletions src/Playwright.TestingHarnessTest/tests/mstest/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ test.describe('ConnectOptions', () => {
const ExampleTestWithConnectOptions = `
using System;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -533,11 +534,9 @@ test.describe('ConnectOptions', () => {
{
await Page.GotoAsync("about:blank");
}
public override PlaywrightConnectOptions ConnectOptions()
public override async Task<(string, BrowserTypeConnectOptions)?> ConnectOptionsAsync()
{
return new() {
WSEndpoint = "http://127.0.0.1:1234",
};
return ("http://127.0.0.1:1234", null);
}
}`;

Expand Down
7 changes: 3 additions & 4 deletions src/Playwright.TestingHarnessTest/tests/nunit/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ test.describe('ConnectOptions', () => {
const ExampleTestWithConnectOptions = `
using System;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
Expand All @@ -526,11 +527,9 @@ test.describe('ConnectOptions', () => {
await Page.GotoAsync("about:blank");
}
public override PlaywrightConnectOptions ConnectOptions()
public override async Task<(string, BrowserTypeConnectOptions)?> ConnectOptionsAsync()
{
return new() {
WSEndpoint = "http://127.0.0.1:1234",
};
return ("http://127.0.0.1:1234", null);
}
}`;

Expand Down
9 changes: 5 additions & 4 deletions src/Playwright.TestingHarnessTest/tests/xunit/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,21 +563,22 @@ test.describe('ConnectOptions', () => {
const ExampleTestWithConnectOptions = `
using System;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.Xunit;
using Xunit;
namespace Playwright.TestingHarnessTest.Xunit;
public class <class-name> : PageTest
{
[Fact]
public async Task Test()
{
await Page.GotoAsync("about:blank");
}
public override PlaywrightConnectOptions ConnectOptions()
public override async Task<(string, BrowserTypeConnectOptions)?> ConnectOptionsAsync()
{
return new() {
WSEndpoint = "http://127.0.0.1:1234",
};
return ("http://127.0.0.1:1234", null);
}
}`;

Expand Down
10 changes: 5 additions & 5 deletions src/Playwright.Xunit/BrowserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ private BrowserService(IBrowser browser)
Browser = browser;
}

public static Task<BrowserService> Register(WorkerAwareTest test, IBrowserType browserType, PlaywrightConnectOptions? connectOptions)
public static Task<BrowserService> Register(WorkerAwareTest test, IBrowserType browserType, (string, BrowserTypeConnectOptions?)? connectOptions)
{
return test.RegisterService("Browser", async () => new BrowserService(await CreateBrowser(browserType, connectOptions).ConfigureAwait(false)));
}

private static async Task<IBrowser> CreateBrowser(IBrowserType browserType, PlaywrightConnectOptions? connectOptions)
private static async Task<IBrowser> CreateBrowser(IBrowserType browserType, (string WSEndpoint, BrowserTypeConnectOptions? Options)? connectOptions)
{
if (connectOptions != null)
if (connectOptions.HasValue && connectOptions.Value.WSEndpoint != null)
{
var options = new BrowserTypeConnectOptions(connectOptions);
var options = new BrowserTypeConnectOptions(connectOptions?.Options ?? new());
var headers = options.Headers?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) ?? [];
headers.Add("x-playwright-launch-options", JsonSerializer.Serialize(PlaywrightSettingsProvider.LaunchOptions, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }));
options.Headers = headers;
return await browserType.ConnectAsync(connectOptions.WSEndpoint, options).ConfigureAwait(false);
return await browserType.ConnectAsync(connectOptions.Value.WSEndpoint, options).ConfigureAwait(false);
}

var legacyBrowser = await ConnectBasedOnEnv(browserType);
Expand Down
5 changes: 1 addition & 4 deletions src/Playwright.Xunit/BrowserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,5 @@ public override async Task DisposeAsync()
await base.DisposeAsync().ConfigureAwait(false);
}

public virtual Task<PlaywrightConnectOptions?> ConnectOptionsAsync()
{
return Task.FromResult<PlaywrightConnectOptions?>(null);
}
public virtual Task<(string, BrowserTypeConnectOptions?)?> ConnectOptionsAsync() => null!;
}

0 comments on commit 86fea44

Please sign in to comment.