using Microsoft.Playwright; using Shouldly; using Xunit; namespace ZB.MOM.WW.OtOpcUa.Admin.E2ETests; /// /// Phase 6.4 UnsTab drag-drop E2E smoke (task #199). This PR lands the Playwright + /// WebApplicationFactory-equivalent scaffolding so future E2E coverage builds on it /// rather than setting it up from scratch. /// /// /// /// Prerequisite. Chromium must be installed locally: /// pwsh tests/ZB.MOM.WW.OtOpcUa.Admin.E2ETests/bin/Debug/net10.0/playwright.ps1 install chromium. /// When the binary is missing the tests rather than fail hard, /// so CI pipelines that don't run the install step still report green. /// /// /// Current scope. The host-reachability smoke below proves the infra works: /// Kestrel-on-a-free-port, InMemory DbContext swap, /// bypass, and Playwright-to-real-browser are all exercised. The actual drag-drop /// interactive assertion is filed as a follow-up (task #242) because /// Blazor Server interactive render through a test-owned pipeline needs a dedicated /// diagnosis pass — the scaffolding lands here first so that follow-up can focus on /// the Blazor-specific wiring instead of rebuilding the harness. /// /// [Trait("Category", "E2E")] public sealed class UnsTabDragDropE2ETests { [Fact] public async Task Admin_host_serves_HTTP_via_Playwright_scaffolding() { await using var app = new AdminWebAppFactory(); await app.StartAsync(); PlaywrightFixture fixture; try { fixture = new PlaywrightFixture(); await fixture.InitializeAsync(); } catch (PlaywrightBrowserMissingException) { Assert.Skip("Chromium not installed. Run playwright.ps1 install chromium."); return; } try { var ctx = await fixture.Browser.NewContextAsync(); var page = await ctx.NewPageAsync(); // Navigate to the root. We only assert the host is live + returns HTML — not // that the Blazor Server interactive render has booted. Booting the interactive // circuit in a test-owned pipeline is task #242. var response = await page.GotoAsync(app.BaseUrl); response.ShouldNotBeNull(); response!.Status.ShouldBeLessThan(500, $"Admin host returned HTTP {response.Status} at root — scaffolding broken"); // Static HTML shell should at least include the and some content. This // rules out 404s + verifies the MapRazorComponents route pipeline is wired. var body = await page.Locator("body").InnerHTMLAsync(); body.Length.ShouldBeGreaterThan(0, "empty body = routing pipeline didn't hit Razor"); } finally { await fixture.DisposeAsync(); } } }