Skip to content

Commit 7166a5e

Browse files
authored
[tests] Some Playwright related fixes (dotnet#4726)
* [tests] Move HasPlaywrightSupport to PlaywrightProvider class * Fix condition disabling playwright based tests
1 parent de442ac commit 7166a5e

9 files changed

+12
-11
lines changed

tests/Aspire.Workload.Tests/EmptyTemplateRunTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public EmptyTemplateRunTests(EmptyTemplateRunFixture fixture, ITestOutputHelper
1717
}
1818

1919
[Fact]
20-
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(BuildEnvironment), nameof(BuildEnvironment.HasPlaywrightSupport))]
20+
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(PlaywrightProvider), nameof(PlaywrightProvider.DoesNotHavePlaywrightSupport))]
2121
public async Task ResourcesShowUpOnDashboad()
2222
{
2323
await using var context = await CreateNewBrowserContextAsync();

tests/Aspire.Workload.Tests/PerTestFrameworkTemplatesTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task TemplatesForIndividualTestFrameworks(string prefix)
5050
buildEnvironment: BuildEnvironment.ForDefaultFramework);
5151

5252
await project.BuildAsync(extraBuildArgs: [$"-c {config}"]).ConfigureAwait(false);
53-
if (BuildEnvironment.HasPlaywrightSupport)
53+
if (PlaywrightProvider.HasPlaywrightSupport)
5454
{
5555
await using (var context = await CreateNewBrowserContextAsync())
5656
{

tests/Aspire.Workload.Tests/StarterTemplateProjectNamesTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task StarterTemplateWithTest_ProjectNames(string prefix, string tes
4040
BuildEnvironment.ForDefaultFramework,
4141
$"-t {testType}").ConfigureAwait(false);
4242

43-
await using var context = BuildEnvironment.HasPlaywrightSupport ? await CreateNewBrowserContextAsync() : null;
43+
await using var context = PlaywrightProvider.HasPlaywrightSupport ? await CreateNewBrowserContextAsync() : null;
4444
_testOutput.WriteLine($"Checking the starter template project");
4545
await AssertStarterTemplateRunAsync(context, project, config, _testOutput).ConfigureAwait(false);
4646

tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public StarterTemplateRunTestsBase(T fixture, ITestOutputHelper testOutput)
2222
}
2323

2424
[Fact]
25-
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(BuildEnvironment), nameof(BuildEnvironment.HasPlaywrightSupport))]
25+
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(PlaywrightProvider), nameof(PlaywrightProvider.DoesNotHavePlaywrightSupport))]
2626
public async Task ResourcesShowUpOnDashboad()
2727
{
2828
await using var context = await CreateNewBrowserContextAsync();
@@ -35,7 +35,7 @@ await CheckDashboardHasResourcesAsync(
3535
[Theory]
3636
[InlineData("http://")]
3737
[InlineData("https://")]
38-
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(BuildEnvironment), nameof(BuildEnvironment.HasPlaywrightSupport))]
38+
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(PlaywrightProvider), nameof(PlaywrightProvider.DoesNotHavePlaywrightSupport))]
3939
public async Task WebFrontendWorks(string urlPrefix)
4040
{
4141
await using var context = await CreateNewBrowserContextAsync();

tests/Aspire.Workload.Tests/TemplateTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task BuildAndRunAspireTemplate(string config)
5050
await project.BuildAsync(extraBuildArgs: [$"-c {config}"]);
5151
await project.StartAppHostAsync(extraArgs: [$"-c {config}"]);
5252

53-
if (BuildEnvironment.HasPlaywrightSupport)
53+
if (PlaywrightProvider.HasPlaywrightSupport)
5454
{
5555
await using var context = await CreateNewBrowserContextAsync();
5656
var page = await project.OpenDashboardPageAsync(context);
@@ -70,7 +70,7 @@ public async Task StarterTemplateNewAndRunWithoutExplicitBuild(string config)
7070
_testOutput,
7171
buildEnvironment: BuildEnvironment.ForDefaultFramework);
7272

73-
await using var context = BuildEnvironment.HasPlaywrightSupport ? await CreateNewBrowserContextAsync() : null;
73+
await using var context = PlaywrightProvider.HasPlaywrightSupport ? await CreateNewBrowserContextAsync() : null;
7474
await AssertStarterTemplateRunAsync(context, project, config, _testOutput);
7575
}
7676

@@ -100,7 +100,7 @@ public async Task ProjectWithNoHTTPSRequiresExplicitOverrideWithEnvironmentVaria
100100
testSpecificBuildEnvironment.EnvVars["ASPIRE_ALLOW_UNSECURED_TRANSPORT"] = "true";
101101
await project.StartAppHostAsync();
102102

103-
if (BuildEnvironment.HasPlaywrightSupport)
103+
if (PlaywrightProvider.HasPlaywrightSupport)
104104
{
105105
await using var context = await CreateNewBrowserContextAsync();
106106
var page = await project.OpenDashboardPageAsync(context);

tests/Aspire.Workload.Tests/WorkloadTestsBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private static IBrowser CreateBrowser()
3434
}
3535

3636
public static Task<IBrowserContext> CreateNewBrowserContextAsync()
37-
=> BuildEnvironment.HasPlaywrightSupport
37+
=> PlaywrightProvider.HasPlaywrightSupport
3838
? Browser.Value.NewContextAsync(new BrowserNewContextOptions { IgnoreHTTPSErrors = true })
3939
: throw new InvalidOperationException("Playwright is not available");
4040

tests/Shared/Playwright/PlaywrightProvider.cs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class PlaywrightProvider
1111
public const string BrowserPathEnvironmentVariableName = "BROWSER_PATH";
1212
private const string PlaywrightBrowsersPathEnvironmentVariableName = "PLAYWRIGHT_BROWSERS_PATH";
1313

14+
public static bool DoesNotHavePlaywrightSupport => Environment.GetEnvironmentVariable("DISABLE_PLAYWRIGHT_TESTS") is "true";
15+
public static bool HasPlaywrightSupport => !DoesNotHavePlaywrightSupport;
16+
1417
public static async Task<IBrowser> CreateBrowserAsync(BrowserTypeLaunchOptions? options = null)
1518
{
1619
var playwright = await Playwright.CreateAsync();

tests/Shared/WorkloadTesting/BuildEnvironment.cs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class BuildEnvironment
2525
public const TestTargetFramework DefaultTargetFramework = TestTargetFramework.Net80;
2626
public static readonly string TestDataPath = Path.Combine(AppContext.BaseDirectory, "data");
2727
public static readonly string TestRootPath = Path.Combine(Path.GetTempPath(), "testroot");
28-
public static bool HasPlaywrightSupport => !EnvironmentVariables.DisablePlaywrightTests;
2928

3029
public static bool IsRunningOnHelix => Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT") is not null;
3130
public static bool IsRunningOnCIBuildMachine => Environment.GetEnvironmentVariable("BUILD_BUILDID") is not null;

tests/Shared/WorkloadTesting/EnvironmentVariables.cs

-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ public static class EnvironmentVariables
1717
public static readonly string? TestAssetsPath = Environment.GetEnvironmentVariable("TEST_ASSETS_PATH");
1818
public static readonly string? TestScenario = Environment.GetEnvironmentVariable("TEST_SCENARIO");
1919
public static readonly string? BrowserPath = Environment.GetEnvironmentVariable(PlaywrightProvider.BrowserPathEnvironmentVariableName);
20-
public static readonly bool DisablePlaywrightTests = Environment.GetEnvironmentVariable("DISABLE_PLAYWRIGHT_TESTS") is "true";
2120
}

0 commit comments

Comments
 (0)