Skip to content

feat: add support for xUnit.v3 #3097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Playwright.TestAdapter/PlaywrightSettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

using System;
using System.Text.Json;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
Expand All @@ -35,6 +36,22 @@ public class PlaywrightSettingsProvider : ISettingsProvider
{
private static PlaywrightSettingsXml? _settings = null!;

public static void LoadViaEnvIfNeeded()
{
if (_settings == null)
{
var settings = Environment.GetEnvironmentVariable("PW_INTERNAL_ADAPTER_SETTINGS");
if (!string.IsNullOrEmpty(settings))
{
_settings = JsonSerializer.Deserialize<PlaywrightSettingsXml>(settings);
}
else
{
_settings = new PlaywrightSettingsXml();
}
}
}

public static string BrowserName
{
get
Expand Down Expand Up @@ -103,5 +120,10 @@ private static void ValidateBrowserName(string browserName, string fromText, str
}

public void Load(XmlReader reader)
=> _settings = new PlaywrightSettingsXml(reader);
{
// NOTE: ISettingsProvider::Load is not called when there are no runsettings (either file or passed via command line).
_settings = new PlaywrightSettingsXml(reader);
Environment.SetEnvironmentVariable("PW_INTERNAL_ADAPTER_SETTINGS", JsonSerializer.Serialize(_settings));
}
}

14 changes: 9 additions & 5 deletions src/Playwright.TestAdapter/PlaywrightSettingsXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ namespace Microsoft.Playwright.TestAdapter;

public class PlaywrightSettingsXml
{
public PlaywrightSettingsXml()
{
}

public PlaywrightSettingsXml(XmlReader reader)
{
// Skip Playwright root Element
Expand Down Expand Up @@ -159,10 +163,10 @@ private static object ParseAsJson(string value, Type type)
return JsonSerializer.Deserialize(value.Replace('\'', '"'), type)!;
}

public BrowserTypeLaunchOptions? LaunchOptions { get; private set; }
public string? BrowserName { get; private set; }
public bool? Headless { get; private set; }
public float? ExpectTimeout { get; private set; }
public int? Retries { get; private set; }
public BrowserTypeLaunchOptions? LaunchOptions { get; set; }
public string? BrowserName { get; set; }
public bool? Headless { get; set; }
public float? ExpectTimeout { get; set; }
public int? Retries { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\Playwright\Playwright.csproj" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />

<!-- MSTest -->
<ProjectReference Include="..\Playwright.MSTest\Playwright.MSTest.csproj" Condition="'$(TEST_MODE)' == 'mstest'" />
Expand All @@ -26,6 +26,11 @@
<ProjectReference Include="..\Playwright.Xunit\Playwright.Xunit.csproj" Condition="'$(TEST_MODE)' == 'xunit'" />
<PackageReference Include="xunit" Version="2.9.2" Condition="'$(TEST_MODE)' == 'xunit'" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" Condition="'$(TEST_MODE)' == 'xunit'" />

<!-- xUnit.v3 -->
<ProjectReference Include="..\Playwright.Xunit.v3\Playwright.Xunit.v3.csproj" Condition="'$(TEST_MODE)' == 'xunit.v3'" />
<PackageReference Include="xunit.v3" Version="2.0.0" Condition="'$(TEST_MODE)' == 'xunit.v3'" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" Condition="'$(TEST_MODE)' == 'xunit.v3'" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright.TestingHarnessTest/tests/baseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type RunResult = {

export const test = base.extend<{
proxyServer: ProxyServer;
testMode: 'nunit' | 'mstest' | 'xunit';
testMode: 'nunit' | 'mstest' | 'xunit' | 'xunit.v3';
runTest: (files: Record<string, string>, command: string, env?: NodeJS.ProcessEnv) => Promise<RunResult>;
launchServer: ({ port: number }) => Promise<void>;
}>({
Expand Down
Loading