-
-
Notifications
You must be signed in to change notification settings - Fork 229
test(blazor): Add Playwright E2E tests for navigation breadcrumbs #4908
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5e4471d
Update solution filters
jamescrosswell 173c2c9
Fixing my mess
jamescrosswell df8aade
test(blazor): Add Playwright E2E tests for navigation breadcrumbs
bruno-garcia b2a1015
Add Playwright test projects to solution and regenerate filters
bruno-garcia 7bae6d8
Increase Blazor WASM test app startup timeout to 120s
bruno-garcia e902aa4
Improve test app startup: capture output, detect early exit, 180s tim…
bruno-garcia d68af9b
Remove --no-build from dotnet run for test app
bruno-garcia 8e06c82
Install Playwright Chromium in test setup
bruno-garcia 3bf7701
Exclude Playwright tests from CI solution filters
bruno-garcia 485775a
Address PR review comments
bruno-garcia 61bdf98
Add Playwright test projects to SLNX solution files
bruno-garcia 16c7fe3
ci: Add Playwright workflow for Blazor WASM E2E tests
bruno-garcia 55bc42d
Address PR review feedback
bruno-garcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: Blazor WASM Playwright Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - release/* | ||
| pull_request: | ||
| paths: | ||
| - 'src/*' | ||
| - 'src/Sentry/**' | ||
| - 'src/Sentry.AspNetCore/**' | ||
| - 'src/Sentry.AspNetCore.Blazor.WebAssembly/**' | ||
| - 'src/Sentry.Extensions.Logging/**' | ||
| - 'test/*' | ||
| - 'test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/**' | ||
bruno-garcia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - 'test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/**' | ||
| - 'test/Sentry.Testing/**' | ||
| - 'global.json' | ||
| - 'Directory.Build.props' | ||
| - 'Directory.Build.targets' | ||
| - 'nuget.config' | ||
| - '.github/workflows/playwright-blazor-wasm.yml' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| playwright: | ||
| name: Blazor WASM E2E | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| DOTNET_CLI_TELEMETRY_OPTOUT: 1 | ||
| DOTNET_NOLOGO: 1 | ||
| steps: | ||
| - name: Cancel Previous Runs | ||
| if: github.ref_name != 'main' && !startsWith(github.ref_name, 'release/') | ||
| uses: styfle/cancel-workflow-action@3155a141048f8f89c06b4cdae32e7853e97536bc # 0.13.0 | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Install .NET SDK | ||
| uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1 | ||
| with: | ||
| global-json-file: global.json | ||
|
|
||
| - name: Install .NET Workloads | ||
| run: dotnet workload restore --temp-dir "${{ runner.temp }}" --skip-sign-check | ||
|
|
||
| - name: Build | ||
| run: dotnet build test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests -c Release | ||
|
|
||
| - name: Install Playwright Browsers | ||
| run: pwsh test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/bin/Release/net10.0/playwright.ps1 install chromium --with-deps | ||
|
|
||
| - name: Run Playwright Tests | ||
| run: dotnet test test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests -c Release --no-build --logger "trx;LogFileName=results.trx" | ||
|
|
||
| - name: Upload Test Results | ||
| if: failure() | ||
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | ||
| with: | ||
| name: playwright-blazor-wasm-results | ||
| path: test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/TestResults/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/App.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Router AppAssembly="@typeof(App).Assembly"> | ||
| <Found Context="routeData"> | ||
| <RouteView RouteData="@routeData" DefaultLayout="@typeof(Shared.MainLayout)" /> | ||
| </Found> | ||
| <NotFound> | ||
| <p>Not found</p> | ||
| </NotFound> | ||
| </Router> |
3 changes: 3 additions & 0 deletions
3
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Directory.Build.props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Project> | ||
| <!-- Stop inheriting test-specific props from test/Directory.Build.props --> | ||
| </Project> |
3 changes: 3 additions & 0 deletions
3
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Directory.Build.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Project> | ||
| <!-- Stop inheriting test-specific targets from test/Directory.Build.targets --> | ||
| </Project> |
4 changes: 4 additions & 0 deletions
4
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Pages/Index.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @page "/" | ||
|
|
||
| <h1 id="page-title">Home</h1> | ||
| <a href="second" id="nav-second">Go to Second</a> |
4 changes: 4 additions & 0 deletions
4
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Pages/Second.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @page "/second" | ||
|
|
||
| <h1 id="page-title">Second Page</h1> | ||
| <a href="trigger-capture" id="nav-trigger">Go to Trigger</a> |
11 changes: 11 additions & 0 deletions
11
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Pages/TriggerCapture.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| @page "/trigger-capture" | ||
|
|
||
| <h1 id="page-title">Trigger Capture</h1> | ||
| <button id="btn-capture" @onclick="Capture">Capture Message</button> | ||
|
|
||
| @code { | ||
| private void Capture() | ||
| { | ||
| SentrySdk.CaptureMessage("playwright-test"); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Microsoft.AspNetCore.Components.Web; | ||
| using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
| using Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp; | ||
|
|
||
| var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
| builder.UseSentry(options => | ||
| { | ||
| // Fake DSN — Playwright intercepts requests before they reach the network | ||
| options.Dsn = "https://key@o0.ingest.sentry.io/0"; | ||
| options.AutoSessionTracking = false; | ||
| }); | ||
|
|
||
| builder.RootComponents.Add<App>("#app"); | ||
| builder.RootComponents.Add<HeadOutlet>("head::after"); | ||
|
|
||
| await builder.Build().RunAsync(); |
17 changes: 17 additions & 0 deletions
17
...aywrightTests.TestApp/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <IsTestProject>false</IsTestProject> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" PrivateAssets="all" /> | ||
| <ProjectReference Include="..\..\src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
5 changes: 5 additions & 0 deletions
5
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/Shared/MainLayout.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @inherits LayoutComponentBase | ||
|
|
||
| <main> | ||
| @Body | ||
| </main> |
4 changes: 4 additions & 0 deletions
4
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/_Imports.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @using Microsoft.AspNetCore.Components.Routing | ||
| @using Microsoft.AspNetCore.Components.Web | ||
| @using Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp | ||
| @using Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.Shared |
16 changes: 16 additions & 0 deletions
16
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp/wwwroot/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Playwright Test App</title> | ||
| <base href="/" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="app">Loading...</div> | ||
| <script src="_framework/blazor.webassembly.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
92 changes: 92 additions & 0 deletions
92
test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/BlazorWasmTestApp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| using System.Collections.Concurrent; | ||
| using System.Diagnostics; | ||
| using System.Net; | ||
| using System.Net.Sockets; | ||
|
|
||
| namespace Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests; | ||
|
|
||
| internal sealed class BlazorWasmTestApp : IAsyncDisposable | ||
| { | ||
| private Process? _process; | ||
| private readonly ConcurrentQueue<string> _output = new(); | ||
|
|
||
| public string BaseUrl { get; private set; } = null!; | ||
|
|
||
| public async Task StartAsync() | ||
| { | ||
| var port = GetFreePort(); | ||
bruno-garcia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BaseUrl = $"http://localhost:{port}"; | ||
|
|
||
| var projectPath = Path.GetFullPath( | ||
| Path.Combine(AppContext.BaseDirectory, | ||
| "..", "..", "..", "..", | ||
| "Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp")); | ||
|
|
||
| _process = new Process | ||
| { | ||
| StartInfo = new ProcessStartInfo | ||
| { | ||
| FileName = "dotnet", | ||
| Arguments = $"run --project \"{projectPath}\" --configuration Release --urls {BaseUrl}", | ||
| RedirectStandardOutput = true, | ||
| RedirectStandardError = true, | ||
| UseShellExecute = false, | ||
| } | ||
| }; | ||
| _process.OutputDataReceived += (_, e) => { if (e.Data != null) _output.Enqueue($"[stdout] {e.Data}"); }; | ||
| _process.ErrorDataReceived += (_, e) => { if (e.Data != null) _output.Enqueue($"[stderr] {e.Data}"); }; | ||
| _process.Start(); | ||
| _process.BeginOutputReadLine(); | ||
| _process.BeginErrorReadLine(); | ||
|
|
||
| using var http = new HttpClient(); | ||
| var timeout = TimeSpan.FromSeconds(180); | ||
bruno-garcia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var sw = Stopwatch.StartNew(); | ||
| while (sw.Elapsed < timeout) | ||
| { | ||
| if (_process.HasExited) | ||
| { | ||
| var logs = string.Join(Environment.NewLine, _output); | ||
| throw new InvalidOperationException( | ||
| $"Blazor WASM test app exited with code {_process.ExitCode} before becoming ready. Output:{Environment.NewLine}{logs}"); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var response = await http.GetAsync(BaseUrl); | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| return; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // Server not ready yet | ||
| } | ||
| await Task.Delay(500); | ||
| } | ||
|
|
||
| var timeoutLogs = string.Join(Environment.NewLine, _output); | ||
| throw new TimeoutException( | ||
| $"Blazor WASM test app did not start within {(int)timeout.TotalSeconds}s at {BaseUrl}. Output:{Environment.NewLine}{timeoutLogs}"); | ||
| } | ||
|
|
||
| private static int GetFreePort() | ||
| { | ||
| using var listener = new TcpListener(IPAddress.Loopback, 0); | ||
| listener.Start(); | ||
| var port = ((IPEndPoint)listener.LocalEndpoint).Port; | ||
| listener.Stop(); | ||
| return port; | ||
| } | ||
|
|
||
| public async ValueTask DisposeAsync() | ||
| { | ||
| if (_process is { HasExited: false }) | ||
| { | ||
| _process.Kill(entireProcessTree: true); | ||
| await _process.WaitForExitAsync(); | ||
| } | ||
| _process?.Dispose(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.