Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ _dependentPackages/
!/xml/System.IO.Log/
!/xml/System.Net.Cache/

# Playwright dependencies
**/*/playwright-deps

# Visual Studio Code
.vscode/*
!.vscode/extensions.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Aspire.Dashboard.ScreenCapture;

public class AppHostTestFixture : IAsyncLifetime
{
public PlaywrightFixture PlaywrightFixture { get; } = new();

public DistributedApplication? App { get; private set; }

public async Task<DistributedApplication> ConfigureAsync<TEntryPoint>(
string[]? args = null,
Action<IDistributedApplicationTestingBuilder>? configureBuilder = null) where TEntryPoint : class
{
var builder = await DistributedApplicationTestingBuilder.CreateAsync<TEntryPoint>(
args: args ?? [],
configureBuilder: static (options, _) =>
{
options.DisableDashboard = false;
});

builder.Configuration["ASPIRE_ALLOW_UNSECURED_TRANSPORT"] = "true";

configureBuilder?.Invoke(builder);

App = await builder.BuildAsync();

await App.StartAsync();

return App;
}

public async Task InitializeAsync()
{
await PlaywrightFixture.InitializeAsync();
}

public async Task DisposeAsync()
{
await PlaywrightFixture.DisposeAsync();

await (App?.DisposeAsync() ?? ValueTask.CompletedTask);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InstallBrowsersForPlaywright Condition="'$(InstallBrowsersForPlaywright)' == '' and '$(ContinuousIntegrationBuild)' == 'true'">true</InstallBrowsersForPlaywright>
<InstallBrowsersForPlaywright Condition="'$(InstallBrowsersForPlaywright)' == '' and '$(OS)' == 'Windows_NT' and '$(ContinuousIntegrationBuild)' != 'true'">true</InstallBrowsersForPlaywright>
<PlaywrightDependenciesDirectory>$(OutputPath)/playwright-deps</PlaywrightDependenciesDirectory>
<HasRuntimeOutput>true</HasRuntimeOutput>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Aspire.Hosting.Testing" Version="9.2.0-preview.1.25202.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="9.0.3" />
<PackageReference Include="Microsoft.Playwright" Version="1.51.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<BrowsersForPlaywrightToInstall Include="chromium" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AspireSample\AspireSample.AppHost\AspireSample.AppHost.csproj" />
</ItemGroup>

<Target Name="ProvisionBrowsersForPlaywright" AfterTargets="Build" Condition="'$(InstallBrowsersForPlaywright)' == 'true'">
<PropertyGroup>
<_MicrosoftPlaywrightDllPath>$(OutputPath)/Microsoft.Playwright.dll</_MicrosoftPlaywrightDllPath>
<_MicrosoftPlaywrightScriptPath>$(OutputPath)/playwright.ps1</_MicrosoftPlaywrightScriptPath>
</PropertyGroup>

<Error Condition="!Exists('$(_MicrosoftPlaywrightDllPath)')" Text="Could not find %24(_MicrosoftPlaywrightDllPath)=$(_MicrosoftPlaywrightDllPath). This expects the project to reference the Microsoft.Playwright nuget." />

<ItemGroup>
<_EnvVarsForPlaywrightInstall Include="PLAYWRIGHT_BROWSERS_PATH=$(PlaywrightDependenciesDirectory)" />
<_EnvVarsForPlaywrightInstall Condition="'$(ContinuousIntegrationBuild)' == 'true'" Include="PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true" />
</ItemGroup>

<Exec Command="powershell -NoProfile -ExecutionPolicy Bypass -File &quot;$(_MicrosoftPlaywrightScriptPath)&quot; install @(BrowsersForPlaywrightToInstall)" EnvironmentVariables="@(_EnvVarsForPlaywrightInstall)" />
</Target>

</Project>
Loading
Loading